T
TanStack2y ago
adverse-sapphire

Is it possible to add a route to the routeTree?

I have a developer tool that I want to add to the route tree if the user is whitelisted for the tool. In this case, I only have access to the routeTree , I have tried casting routeTree to a Route and calling routeTree.addChildren but it results in losing in all my routes.
5 Replies
metropolitan-bronze
metropolitan-bronze2y ago
I would add it to the tree regardless, and add some sort of check within that route that redirects the user to their previous route if they aren't whitelisted
quickest-silver
quickest-silver2y ago
^ yup. You can use the beforeLoad callback to check if the user has the right permissions to even load the route and if not, throw a redirect.
adverse-sapphire
adverse-sapphireOP2y ago
That works but I am building a library and I don't want the consumer to worry about the tool. So is there any way to add the route to the routeTree ?
quickest-silver
quickest-silver2y ago
If you really want full control, you could use router.update to update the tree, but you'll pretty much definitely be opting-out of the type-inference at this point since your route-tree wouldn't inferable at this point. Even as a library, you'd be better off exposing a function/callback that executed in the beforeLoad callback for the route for this devtools panel.
adverse-sapphire
adverse-sapphireOP2y ago
Thank you for the router.update clue. The issue I am having is how to add a route dynamically to the routeTree. I tried .addChildren but I get errors.

Did you find this page helpful?