Description
Right now it is possible to dynamically add routes by calling router.addRoutes([/* routes */])
. It would be nice if it was possible to also remove/replace routes on the fly. In my app user may define routes by himself (on the fly). I keep user configuration in the Vuex store, and when it is updated I want to completely replace whole router routes configuration (though replacing/removing single route would be also handful but I guess then it should also handle removing/replacing/adding child routes instead of only dealing with top-level routes, which would be quite complicated). I imagine that after replacing routes router would check if current path matches any of the new routes and navigated to it.
It could be for example method router.replaceRoutes([/* routes */])
or router.setRoutes
(in addition to method router.addRoutes
which already exists).
Please note that this situation can be handled without VueRouter by setting one global route /*
that will match every possible path, performing route matching inside this global route component (based on dynamic config stored in Vuex store for example) and dynamic rendering of component(s) that matched current path. However this is very ugly solution which looses all benefits of VueRouter, and handling child routes would be complicated.
In fact I wanted to handle it by patching VueRouter manually, but it seems that createMatcher
(https://github.com/vuejs/vue-router/blob/dev/src/create-matcher.js#L16) does not expose pathMap
and nameMap
so it is not possible modify routes configuration in other way than by calling router.addRoutes
(I guess it's intentional :).