createLazyFileRoute with beforeLoad #2253
-
Hi, I am using createLazyFileRoute to lazy load bunch of my routes, but I would also like to use beforeLoad for RBAC before navigating to a page. It looks like beforeLoad is not available for lazy routes and I have to use createFileRoute which has beforeLoad available. Currently, I would like to do somethin like below:
Is there an option where I can use both lazy loading + beforeLoad to handle RBAC? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I found this link for virtual routes. Does this mean that I have to 2 files (1 createFileRoute and 1 createLazyFileRoute) for every single route that needs beforeLoad? |
Beta Was this translation helpful? Give feedback.
the section above that is the most relevant one for you: https://tanstack.com/router/latest/docs/framework/react/guide/code-splitting#example-code-splitting-with-lazytsx
and yes, you create 2 files in that case.
alternatively, you could also enable automatic code splitting so you don't have to do anything manually.