how to respond to changes in $router.getRoutes() #1942
-
Im interested in dynamically adding routes to an application depending on whether a user is authenticated or not. I find I can do this on mounted in App.vue with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I would recommend you not to do that because there isn't any benefit from conditionally adding routes, it just makes things more complicated. Instead, add a navigation guard that cancels the navigation to these routes if the user is not authenticated. |
Beta Was this translation helpful? Give feedback.
It's unlikely to have an impact in your bundle size as the routes definitions themselves are pretty small. You can still give it a try but you can lazy load any modules within navigation guards to keep route definitions to 0 dependencies.