#Wondering how to setup this structure via Directory routes?

5 messages · Page 1 of 1 (latest)

limber girder
#

Say I got these routes:

/
/auth/login
/whatever

I've got a beforeLoad checking my session on __root.tsx which is fine and re-directs to /auth/login. But /auth/login also has to wait on the beforeLoad from root so it won't render (it triggers a warning actually: "Tried to render a redirected route match! This is a weird circumstance, please file an issue!".

Wondering how you would (if you can) implement it?

zenith flame
#

can you please provide a minimal complete example? e.g. by forking one of the existing examples on stackblitz

limber girder
#

Yup sure thing:
https://stackblitz.com/edit/tanstack-router-5hukij?file=src%2Froutes%2F__root.tsx

Now to me this isn't a bug, it's working as intended - the user browses the app, isn't logged in and is re-directed to /auth/login. But I am wondering if using the routes in folder structure approach, if it is possible to not have /auth/login use that "beforeLoad" from __root.

hopefully that makes sense!

Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz

zenith flame
#

maybe you can conditionally check the route in beforeLoad and skip it?

clear briar
#

Don't check the session + redirect on the root route.
Add a layout route _authenticated and check + redirect there.
Then make sure all the routes that should be authenticated are nested underneath.

Mine looks like this:

_root.tsx
_auth.tsx <-- check here!
_auth.index.tsx
_auth.thing.tsx
login.tsx <-- this is not under _auth and thus "public"