- 二级路由配置path时前面不能有 " / "
- 在一级路径信息数组中添加一个children配置项:
{path:'/hot',component:()=>import('@/views/Hot/index'),
children:[
{path:'/',redirect:'film'},
{path:'film',component:{template:'<p>妖猫传</p>'}},
{path:'tv',component:{template:'<p>河神</p>'}},
{path:'music',component:{template:'<p>缘分一道桥</p>'}}
]
}
- 在一级路由的模板中添加,to中的地址需要 加上一级路由
- 供二级路由对应模板显示的也不能忘!
<template id="hot">
<div class="hotWrap">
<h2>Hot</h2>
<router-link to="/hot/film">film</router-link>
<router-link to="/hot/tv">tv</router-link>
<router-link to="/hot/music">music</router-link>
<router-view></router-view>
</div>
</template>