Which project does this relate to?
Router
Context:
I implemented an authenticated route following this guide:
https://tanstack.com/router/latest/docs/framework/react/how-to/setup-authentication#1-set-up-router-context
My setup includes:
Issue Description:
In _authenticated.tsx, I log the context inside beforeLoad like this:
beforeLoad(ctx) {
console.log(ctx);
}
When beforeLoad is triggered from a preload (e.g., when hovering over a link), the ctx value is undefined.
Additionally, once a navigation actually occurs (after clicking a link), the issue disappears — from that point onward, ctx always contains the correct data.
Note that after implementing in stackblitz, I realized it's not necessarly "undefined", instead it's just using an expired value
Summary of Behavior:
| Scenario |
Route |
Trigger |
ctx value |
| Preload (hover intent) |
_authenticated.tsx |
beforeLoad |
no correct |
| After first navigation |
any |
beforeLoad |
✅ Correct |
Expected Behavior:
ctx should be populated correctly in beforeLoad during preloads, even before any navigation has occurred.
Your Example Website or App
https://stackblitz.com/edit/github-f1nanrq2?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
- Open console
- See expected value for context: "baz"
- Mouse hover "Foo" at the top
- See the preload logs containing old value "foo"
- Click "Foo"
- Mouse hover "Foo" again
-
- See the preload logs containing new value "baz"
Expected behavior
first time preload occurs, it should contain the expected value "baz" before navigation.
Screenshots or Videos
Platform
- Router / Start Version: [e.g. 1.121.0]
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Browser Version: [e.g. 91.1]
- Bundler: [e.g. vite]
- Bundler Version: [e.g. 7.0.0]
Additional context
No response
Which project does this relate to?
Router
Context:
I implemented an authenticated route following this guide:
https://tanstack.com/router/latest/docs/framework/react/how-to/setup-authentication#1-set-up-router-context
My setup includes:
_authenticated.tsx— defines abeforeLoadthat checks whether the user is authenticated._authenticated/foo.tsx— a nested route that performs additional logic.Issue Description:
In
_authenticated.tsx, I log the context insidebeforeLoadlike this:When
beforeLoadis triggered from a preload (e.g., when hovering over a link), thectxvalue isundefined.Additionally, once a navigation actually occurs (after clicking a link), the issue disappears — from that point onward,
ctxalways contains the correct data.Note that after implementing in stackblitz, I realized it's not necessarly "undefined", instead it's just using an expired value
Summary of Behavior:
Expected Behavior:
ctxshould be populated correctly inbeforeLoadduring preloads, even before any navigation has occurred.Your Example Website or App
https://stackblitz.com/edit/github-f1nanrq2?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
Expected behavior
first time preload occurs, it should contain the expected value "baz" before navigation.
Screenshots or Videos
Platform
Additional context
No response