how can i access all children pathname from parent route or __root route #3222
-
I’m working on a project using TanStack Router and need help with the following: Managing Layout State via URL: I want to manage the layout state (e.g., showing a sidebar or navbar) based on the URL instead of using context or global state. For example: If the user is on /dashboard, show a sidebar. If the user is on /login, show a default navbar. Currently, I’m using useLocation to check the path and conditionally render the layout components. Is this the best approach? Type-Safe Route Paths: I have a list of paths (sidebarPaths) where the sidebar should be displayed, but I’m defining them manually: typescript Authentication and Route Protection: All routes under /_auth are protected and require authentication. If the user isn’t logged in, they should be redirected to /login. How can I ensure that the sidebarPaths only include valid, authenticated routes? Here’s my current implementation: typescript
Questions:
Any guidance or examples would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
checkout
router.routesByPath