vue-router-sitemap
vue-router-sitemap copied to clipboard
Add support of nested routes
...
routes: [
{ path: '/', redirect: '/parent' },
{ path: '/parent', component: Parent,
children: [
// an empty path will be treated as the default, e.g.
// components rendered at /parent: Root -> Parent -> Default
{ path: '', component: Default },
// components rendered at /parent/foo: Root -> Parent -> Foo
{ path: 'foo', component: Foo },
]
}
]
...
any update on this?
@CheyenneForbes Solved it this way:
const sitemapBuilder = new VueRouterSitemap(router);
sitemapBuilder.paths = parseRoutes(router.options.routes);
// ...
function parseRoutes(routes) {
return routes.reduce((acc, curr) => {
if (curr.children && curr.children.length > 0) {
parseRoutes(curr.children).forEach(c => {
acc.push({
...c,
path: `${curr.path}/${c.path}`
});
});
} else {
acc.push(curr);
}
return acc;
}, []);
}