You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On non-initial loads, when a _layout route's beforeLoads() is triggered by navigation, router.invalidate(), the route's contex returns undefined
Please run vite dev and use Auth Dev Controls to toggle auth state changes and observe the _LAYOUT/context returns undefined
Note:
the routes of the _layout returns the context correctly
the root router's context has the returns context correctly
exportconstRoute=createFileRoute('/_not_authed')({beforeLoad: ({context: { auth }})=>{//If the user is already authenticated, redirect them to the main dashboardif(auth.get()){console.log('redirecting to /')throwredirect({to: '/'})}},component: memo(Component),})functionComponent(){constcontext=Route.useRouteContext()//this returns undefined on non-initial redirectconstrootContext=useRouteContext({from: '__root__'})//this seems to resolveconsole.log('_not_authed/context:',context,rootContext)return(<divclassName="bg-gray-300">
...
</div>)}
Describe the bug
Layout Route Contexts NOT being set on non-initial redirects in beforeLoad()
Repo reproduction
https://github.com/cpakken/issue-tanstack-router-layout-route-context
"@tanstack/react-router": "^1.32.13",
On non-initial loads, when a _layout route's beforeLoads() is triggered by navigation, router.invalidate(), the route's contex returns
undefined
Please run
vite dev
and use Auth Dev Controls to toggle auth state changes and observe the _LAYOUT/context returnsundefined
Note:
No context in _auth
root has context
Your Example Website or App
https://github.com/cpakken/issue-tanstack-router-layout-route-context
Steps to Reproduce the Bug or Issue
See readme.
Expected behavior
Route.useRouteContext() should return the context instead of undefined on non-initial redirects
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: