TanStackT
TanStack12mo ago
1 reply
uncertain-scarlet

running beforeLoad auth in __root.tsx, but which needs access to a Context

basically at the __root i want to run auth checks beforeLoad. in this auth check, however, i need to set context values that will be available to the rest of the app.

in order to wire up context to be available in the beforeLoad, I need the <Provider/> to be wrapping the component, right? but we're at the top level which makes things difficult.

one idea is to update the component property of the Route object to return
component: () => <AuthProvider><Component /><AuthProvider/>. not even sure if this will work

another option is to do a pathless route that is basically a 'sub-root', that does everything the _root does, and then the _root basically isn't doing anything other than rendering providers

sorry this is probably confusing, just wanting to follow best/tried practices for this
image.png
Was this page helpful?