Replies: 1 comment 1 reply
-
|
File-based routing generates the route tree at build time, so you can't conditionally register routes at runtime. But for your use case (backend-driven admin panel), you probably don't need to. The pattern most admin panels use: register all routes statically in the file tree, gate access with // routes/system/user.tsx
export const Route = createFileRoute('/system/user')({
beforeLoad: async ({ context }) => {
if (!context.auth?.hasPermission('system:user')) {
throw redirect({ to: '/403' })
}
},
})Your If routes are truly dynamic (CMS pages, user-created content where the shape is unknown at build time), a splat route ( |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a SPA project where route information is retrieved from the database and registered dynamically. The frontend only has basic pages like 404, login, etc. by default. For example, I receive route data like this from the backend:
When users have admin privileges, I need to dynamically register these routes. However, when using File-based Routes, I cannot control the route registration process. Perhaps I can try to solve it using code-based routing. However, I prefer the file-based route.
If there is a solution, I would be extremely grateful.
Beta Was this translation helpful? Give feedback.
All reactions