`loader` function doesn't have access to `context` after being redirected to
I load a route and check some things in the
loader
function. If it errors, I throw redirect
to another route. That route, however, doesn't seem to have access to the context in its loader
function.
routes/offers.tsx
routes/index.tsx
9 Replies
eastern-cyanOP•17mo ago
It might be worth noting that the
beforeLoad
function DOES have access to context
howeversunny-green•17mo ago
This looks to be related to this issue: https://github.com/TanStack/router/issues/1531
If you've got a reproduction, it'd help being able to pinpoint the issue.
GitHub
Context is undefined after redirect · Issue #1531 · TanStack/router
Describe the bug I use authentication, similar to Authenticated Routes example from documentation. So, when user is on /$lang page, if user is not authorised, user is been redirecting to /$lang/log...
eastern-cyanOP•17mo ago
Ah yes, looks related. Thanks!
fair-rose•17mo ago
I have also encountered this issue. Interesting observation I found, calling the navigate exposed in the beforeLoad callback, does not cause the issue. Not sure if helpful or not
sunny-green•17mo ago
That's probably because navigate directly changes the matches internally.
On the flip-side the fact that it is not preload friendly makes it more of a problem that anything and why its been deprecated.
extended-salmon•16mo ago
@Sean Cassiere @Manuel Schiller the "context is undefined after redirect" issue is back and it's quite easy to reproduce. Can you please have a look here?
https://github.com/TanStack/router/issues/1670#issuecomment-2144897100
GitHub
Undefined context after redirect · Issue #1670 · TanStack/router
Describe the bug Seems like the issue with undefined context is not fully resolved yet. When redirecting I'm seeing undefined context. Some criteria to trigger the issue defaultPreload: 'in...
sunny-green•16mo ago
I'll be online a couple days. Will look into this.
There was a PR opened I think about this. Will check.
other-emerald•16mo ago
Does someone know what version reimplemented this bug ?
correct-apricot•16mo ago
I found another edge case in
v1.34.9
that causes context
to become undefined
if the route that throws the redirect has search params that are being validated through validateSearch
, and the validation fails/throws (e.g. with zod
).
Here's a complete repro:
https://stackblitz.com/edit/tanstack-router-qbczsv?file=src%2Froutes%2Findex.tsxMelvin Valster
StackBlitz
Router Redirect undefined context - StackBlitz
Run official live example code for Router Basic File Based, created by Tanstack on StackBlitz