There is an option to define the routes in the backend, for example in a .json
file, and to load them into Vue app dynamically, something like this:
router.addRoutes([{
path: '/test',
name: 'Test',
component: require('./components/Test'),
}]);
So if there was a service to load the routes from API, we'd have something like:
routesApiService
.getRoutes()
.then(routes => {
const transformedRoutes = routes.map(route => ({
path: route.path,
name: route.name,
component: require(route.componentPath)
}))
router.addRoutes(transformedRoutes)
})
router.addRoutes
was added to VueRouter recently - http://stackoverflow.com/a/42476612 - pretty cool to be able to dynamically load routes!