Authenticated directory routes - unable to get it to work
We had file based routing for the longest time. Now with the ever increasing amount of new routes we'd like to refactor into some directories instead. For a basic example we used to have
With
_auth.tsx containing authentication logic which handles redirects and such.
Now turning it into directories
Moving the authentication logic to /_auth/index.tsx and navigating to the dashboard it skips the logic and goes straight to the dashboard. Is there a way on how all the child directories in /_auth/ must go through that logic before going to their components?4 Replies
like-gold•4w ago
or
unwilling-turquoiseOP•4w ago
Do you have a link to the documentation where it says there? I cant find it anywhere
like-gold•4w ago
There is no one documentation page that explains this IIRC.
but TL;DR
route.tsx is the default behavior of routes, when the route's path is matched, then it is rendered, and they allow nesting.
index.tsx are rather "leaf" routes, they only render when the path exactly matches theirs
Also, to give you more context, the above examples I gave are doing the exact same thing as your initial files only structure
There's the description for the route.tsx notation
https://tanstack.com/router/latest/docs/framework/react/routing/file-naming-conventions
unwilling-turquoiseOP•4w ago
Alrighty i did not know that actually. I probably read over it
Thank you nonetheless