Skip to content
Source
Sign inSign up
TanStack/router

feat: provide location in onEnter/onStay/onLeave hooks #3622

Closedjprosevear(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/3622/headopened

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core

    3. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router

    4. View your CI Pipeline Execution ↗ for commit 406cec67449df42d1a256e69ee8e2c1848bec651.

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...❌ Failed1m 39sView ↗
      nx run-many --target=build --exclude=examples/*...❌ Failed4sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-03-04 21:07:53 UTC

    5. Resolvedby jprosevear(GitHub profile, opens in a new tab)
    6. Open in Stackblitz

      More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@3622

      @tanstack/create-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/create-router@3622

      @tanstack/create-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/create-start@3622

      @tanstack/directive-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@3622

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@3622

      @tanstack/history

      npm i https://pkg.pr.new/TanStack/router/@tanstack/history@3622

      @tanstack/react-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@3622

      @tanstack/react-router-with-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-with-query@3622

      @tanstack/react-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@3622

      @tanstack/react-start-api-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-api-routes@3622

      @tanstack/react-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@3622

      @tanstack/react-start-config

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-config@3622

      @tanstack/react-start-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@3622

      @tanstack/react-start-router-manifest

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-router-manifest@3622

      @tanstack/react-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@3622

      @tanstack/react-start-server-functions-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-client@3622

      @tanstack/react-start-server-functions-fetcher

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-fetcher@3622

      @tanstack/react-start-server-functions-handler

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-handler@3622

      @tanstack/react-start-server-functions-ssr

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server-functions-ssr@3622

      @tanstack/router-cli

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@3622

      @tanstack/router-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@3622

      @tanstack/router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@3622

      @tanstack/router-generator

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@3622

      @tanstack/router-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@3622

      @tanstack/router-utils

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@3622

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@3622

      @tanstack/server-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@3622

      @tanstack/solid-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@3622

      @tanstack/solid-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@3622

      @tanstack/solid-start-api-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-api-routes@3622

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@3622

      @tanstack/solid-start-config

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-config@3622

      @tanstack/solid-start-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@3622

      @tanstack/solid-start-router-manifest

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-router-manifest@3622

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@3622

      @tanstack/solid-start-server-functions-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-client@3622

      @tanstack/solid-start-server-functions-fetcher

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-fetcher@3622

      @tanstack/solid-start-server-functions-handler

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-handler@3622

      @tanstack/solid-start-server-functions-ssr

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server-functions-ssr@3622

      @tanstack/start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start@3622

      @tanstack/start-config

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-config@3622

      @tanstack/start-server-functions-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@3622

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@3622

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@3622

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@3622

      commit: 9d71302

    7. github-actions[bot](GitHub profile, opens in a new tab) added labelsdocumentation

    8. packages/solid-router/tests/route.test.tsx line 195
      @@ -191,3 +191,5 @@
      191191
      192192 expect(fn).toHaveBeenCalledWith({ foo: 'bar' })
      193193 })
      194+
      195+ it('should have location defined in router.load()', async () => {

      rather should have location defined in onEnter?

      please also add a test for onStay and onLeave

      also applies to react-router of course

      Was just copying the style from above

      its in an onEnter describe block

    9. Resolvedby jprosevear(GitHub profile, opens in a new tab)
    10. packages/router-core/src/route.ts line 868
      @@ -865,3 +865,4 @@
      865865 >,
      866866 TLoaderDeps
      867867 >,
      868+ { location }: { location: ParsedLocation<{}> },

      we should be able to supply the search type here (same for the others as well)

      probably makes sense to create a type OnMatchOptions<TSearch> = {location:ParsedLocation<TSearch>

      and use this for all 3 methods?

      i think this additional typing is a little out of my immediate grasp - can you give some more guidance

      before we do that, what is the semantic of location in each of these hooks?

      I think in case of onLeave location is anything BUT the match, so we cannot statically type the search here. whereas for the other hooks, the route's search is present in location

      Its the location that will resolve (assuming nothing thrown) - played with current / next like the useBlocker stuff but decided on this approach.

    11. schiller-manuel(GitHub profile, opens in a new tab)replied on packages/solid-router/tests/route.test.tsx line 195

      also applies to react-router of course

    12. jprosevear(GitHub profile, opens in a new tab)replied on packages/solid-router/tests/route.test.tsx line 195

      Was just copying the style from above

    13. jprosevear(GitHub profile, opens in a new tab)replied on packages/router-core/src/route.ts line 868

      i think this additional typing is a little out of my immediate grasp - can you give some more guidance

    14. jprosevear(GitHub profile, opens in a new tab)replied on packages/solid-router/tests/route.test.tsx line 195

      its in an onEnter describe block

    15. schiller-manuel(GitHub profile, opens in a new tab)replied on packages/router-core/src/route.ts line 868

      before we do that, what is the semantic of location in each of these hooks?

      I think in case of onLeave location is anything BUT the match, so we cannot statically type the search here. whereas for the other hooks, the route's search is present in location

    16. jprosevear(GitHub profile, opens in a new tab)replied on packages/router-core/src/route.ts line 868

      Its the location that will resolve (assuming nothing thrown) - played with current / next like the useBlocker stuff but decided on this approach.

    17. @schiller-manuel how do you want to reconcile this?

    18. Thanks for the PR. I'm closing it because it has fallen behind main (sorry it got lost in the shuffle), and the lifecycle implementation has since moved into router-core.

      The feature is still useful, so we’ve opened #7778 to track a fresh implementation. A new PR based on that issue would be welcome if you are still interested!

Sign in to join this conversation.