Vue路由及嵌套路由

Posted FF盖世英雄CC

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vue路由及嵌套路由相关的知识,希望对你有一定的参考价值。

router.js

import Vue from ‘vue‘
import VueRouter from ‘vue-router‘

Vue.use(VueRouter)

const first = {template:‘<h1>first</h1>‘}
const second = {template:‘<h1>second</h1>‘}
const home = {template:‘<h1>home</h1>‘}
const lala = {
template:`
<div class="lala">
<h2>组件</h2>
<router-view class="lalala"></router-view>
</div>
`
}
const firstfirst = {template:‘<h1>firstfirst</h1>‘}
const secondsecond = {template:‘<h1>secondsecon</h1>‘}

const router=new VueRouter({
mode:‘history‘,
base:__dirname,
routes:[
{path:‘/‘, component:home},
{path:‘/first‘, component:lala,
children:[
{path:‘/first‘, component:firstfirst},
{path:‘/second‘, component:secondsecond}
]
},
{path:‘/second‘, component:second}
]
})
new Vue({
router,
template:` <div id="r">
<h1>导航</h1>
<ol>
<li><router-link to = "/">/</router-link></li>
<li><router-link to = "/first">first</router-link></li>
<ol>
<li><router-link to = "/first">first</router-link></li>
<li><router-link to = "/second">second</router-link></li>
</ol>
<li><router-link to = "/second">second</router-link></li>
</ol>
<router-view> </router-view>
</div>

`}).$mount(‘#app‘)

以上是关于Vue路由及嵌套路由的主要内容,如果未能解决你的问题,请参考以下文章

Vue 默认路由 与路由嵌套

Vue-Router(三):嵌套路由

vue路由嵌套,如何子路由也有选中样式

Vue 嵌套路由路由守卫

vue嵌套路由(父子路由)

vue-cli嵌套路由