vue-router-sitemap icon indicating copy to clipboard operation
vue-router-sitemap copied to clipboard

Add support of nested routes

Open 40818419 opened this issue 6 years ago • 2 comments

...
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 },
      ]
   }
]
...

40818419 avatar May 24 '18 09:05 40818419

any update on this?

CheyenneForbes avatar Jun 19 '20 13:06 CheyenneForbes

@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;
  }, []);
}

mbarouski avatar Apr 08 '21 11:04 mbarouski