DEV Community

Discussion on: Vue Router Architecture and Nested Routes

Collapse
 
sjoerd82 profile image
Sjoerd82

I have used a similar setup, but faced the following problem with it. I have a bunch of routes that all use an EmptyRouterView as base view. This way I wanted to put some reusable logic*, including a dialog box, in the EmptyRouterView (I guess not so empty anymore...). For a while I was fooled into thinking this worked, until I navigated between routes in my SPA, and noticed that the setup() (of the Vue Composition API) was not called anymore!

{
path: '/my-route',
component: EmptyRouterView,
children: [{
path: '',
component: MyRouteView
}]
},
{
path: '/my-other-route',
component: EmptyRouterView,
children: [{
path: '',
component: SomeOtherView
}]
}

It seems that JS/Webpack is too smart and thinks that since it's the same module it does not need any setup() anymore. A real bummer. Idea's?

*) The resusable logic is stuff that's shared by a lot of pages and includes a beforeRouteUpdate (which insists on being placed in the VIEW) and a dialog box that asks if the user wants to discard changes made. Both difficult things to make reusable, I found..