`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
unwilling-turquoiseOP•2y ago
It might be worth noting that the
beforeLoad function DOES have access to context howeverextended-yellow•2y 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...
unwilling-turquoiseOP•2y ago
Ah yes, looks related. Thanks!
passive-yellow•2y 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
extended-yellow•2y 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•2y 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...
extended-yellow•2y ago
I'll be online a couple days. Will look into this.
There was a PR opened I think about this. Will check.
exotic-emerald•2y ago
Does someone know what version reimplemented this bug ?
xenial-black•2y 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