在我的网站上,我有一个导航,其中包含一些类别和嵌套的导航锚点。如何在 vue-router 中对这些路由进行分组?我想出的最好的方法是为每条路线放置一个元数据,然后按它分组。
我这样使用(看那个component: { render: h => h('router-view') }):
{
// =============================================================================
// MAIN LAYOUT ROUTES
// =============================================================================
path: '',
component: () => import('./layouts/main/Main.vue'),
children: [
// =============================================================================
// Routes
// =============================================================================
{
path: '/',
name: 'home',
component: () => import('./views/Dashboard.vue'),
},
// =============================================================================
// User Routes
// =============================================================================
{
path: '/user',
name: 'user',
component: { render: h => h('router-view') },
children: [
{
path: 'list',
name: 'user.list',
component: () => import('./views/pages/User/List.vue'),
},
]
},
],
}
Run Code Online (Sandbox Code Playgroud)
您可以使用嵌套路由。在你的路由文件中你可以做类似的事情。
{
path: '/category',
name: 'category',
component: Category,
children: [
{
path: 'subcategory',
name: 'subCategory',
component: ChildComponent,
},
// other nested routes
]
},
Run Code Online (Sandbox Code Playgroud)