配置路由
{
path: '/about',
name: 'about',
component: () => import( '../views/AboutView.vue')
}
在新建一个和上面路径下的一个组件的一个页面
<template>
<div>
<h1>AboutView</h1>
<router-link to="/childb/three">three</router-link>
<router-view></router-view>
</div>
</template>
<script>
export default {
}
</script>
<style>
</style>
入口页面配置
<template>
<div id="app">
<nav>
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link> |
<router-link to="/childa">childa</router-link> |
<router-link to="/childb">childb</router-link> |
</nav>
<router-view />
</div>
</template>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
}
nav a {
font-weight: bold;
color: #2c3e50;
}
nav a.router-link-exact-active {
color: #42b983;
}
</style>
配置 二级路由
{
path: '/childb',
name: 'childB',
component: () => import( '../views/ChildB.vue'),
children:[{
path: 'three',
name: 'three',
component:()=>import('../views/threeView.vue')
}]
},
在一级路由下需要配置
<router-link to="/childa/two">two</router-link>
<router-view />
redirect:''这个方法可以让一进入页面就显示二级路由