教程上說此時,基于上面的配置,當你訪問 /user/foo 時,User 的出口是不會渲染任何東西,這是因為沒有匹配到合適的子路由。如果你想要渲染點什么,可以提供一個 空的 子路由:訪問 /user/foo 時,User組件是能夠渲染的,只是無法渲染作為子組件的UserProfile和UserPosts。不知道教程為什么說 “User 的出口是不會渲染任何東西”const User = {
template: `
<div class="user"> <h2>User {{ $route.params.id }}</h2>
<router-view></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
}
]
}
]
})
vue router官方教程 嵌套路由里邊的一個疑惑
ibeautiful
2018-07-11 12:15:46