Beginner: wrong beforeload being trigger ?
Hey guys, so I have a file tree as follow:
and whenever I access the page
teams_.$teamId_.invitations_.$token.accept.tsx
the beforeload of teams_.$teamId.tsx
is being called. Is this normal ? if so how could I truned this off.
I tried to look in the docs for this but I couldn't find anything.
Thanks in advanced 🙌16 Replies
rare-sapphire•7mo ago
all beforeLoad functions of all routes that are in the current hierachy are executed upon each navigation
you cannot turn this off
what does it do in your case? there are several options depending on the use case
like-goldOP•7mo ago
Thanks for getting in touch.
I am just using the beforeLoad to check if my user is allowed to view page. But because the beforeLoad of the
/teams/:id
page will get called first, the beforeLoad of the /teams/:id/invitations/:token
page will never be called.
/teams/:id
/teams/:id/invitations/:token
rare-sapphire•7mo ago
sounds like your accept route should not be under the permission check then?
so move it out of there
like-goldOP•7mo ago
so you want me to move it out of the
/(teams)/teams_/$teamId
directory ?rare-sapphire•7mo ago
its parent must be something that does not check the permission
there are other workarounds
like-goldOP•7mo ago
ok I see, but in this case all of the teams routes got a auth check.
rare-sapphire•7mo ago
you could also disable the auth check if the accept is currently matched
rare-sapphire•7mo ago
StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
rare-sapphire•7mo ago
like-goldOP•7mo ago
Awesome, that makes a lot of sense
Thanks for explaining @Manuel Schiller 🙌
rare-sapphire•7mo ago
there are more options for sure
you could also put the auth check into a pathless route
like-goldOP•7mo ago
Yes Indeed, I will play around with the code to see which one fit better
rare-sapphire•7mo ago
StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
like-goldOP•7mo ago
very handy thanks
rare-sapphire•7mo ago
IMO the pathless route is cleaner
but both work
like-goldOP•7mo ago
yes I agree