T
TanStack6mo ago
manual-pink

Tanstack Router Context

Hi all. I’m trying to use the router context but I keep on missing. I’ve got it either set up incorrectly or something is going on. Using the main.tsx file I render the RouterProvider where I also create the router with a context key as empty. But at some point I would like to make a api call that fetches some data that I would lime to store into the router context so that I have it available on every child route in the beforeLoad hook. Is there a example where this is shown in more detail? Because I’m trying the docs way to update the context in the loader but with no luck.
4 Replies
extended-salmon
extended-salmon6mo ago
can you create a minimal recreation in stackblitz or codesandbox?
constant-blue
constant-blue6mo ago
sounds like you should just return the data from some route's (e.g. root route) beforeLoad function so all child routes will inherit this data in their route context
manual-pink
manual-pinkOP6mo ago
@Manuel Schiller you saved me again it seems 😄 Looking at the docs now - I see it 😄
xenial-black
xenial-black6mo ago
Hello @Nate Vukovich, did you make the request in the beforeLoad hook?

Did you find this page helpful?