多层嵌套的前端界面
示例代码
const User = {
template: `
<div class="user">
<!--子路由出口, profile/posts組件 -->
<router-view/>
</div>
`
}
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 相当于 routes 配置一样的路由配置数组;
css 工程化👉 利用 webpack 解析 css
上一篇