v-router嵌套路由
应用界面通常由多层嵌套组件组合而成。同样url各段动态路径也按照某种结构对应嵌套的各层组件。嵌套路由则 可以很好地表达这种关系 。
- 例:
如果在实现上述页面要求时,就会用到嵌套路由。 - 实例:
const router = new VueRouter({
routes: [
{ path: '/user/:id', component: User,
children: [
{
// 当 /user/:id/profile 匹配成功,
// UserProfile 会被渲染在 User 的 <router-view> 中
path: 'profile',
component: UserProfile
},
{
// 当 /user/:id/posts 匹配成功
// UserPosts 会被渲染在 User 的 <router-view> 中
path: 'posts',
component: UserPosts
}
]
}
]
})
- children里也可根据需求继续添加children,开启无限套娃模式。