TanStackT
TanStack2y ago
8 replies
moderate-tomato

Is there a hook to access router context ?

I followed the guide for React Context:
https://tanstack.com/router/latest/docs/framework/react/guide/router-context#router-context

I would like to access the context from a component like this:

const context = useRouterContext();


But I didn't find a way to do it.

Do you have any solution?
TanStack Router's router context is a very powerful tool that can be used for dependency injection among many other things. Aptly named, the router context is passed through the router and down through each matching route. At each route in the hierarchy, the context can be modified or added to. Here's a few ways you might use the router context...
Router Context | TanStack Router React Docs
Was this page helpful?