import Home from ‘../components/Home.vue‘
import About from ‘../components/About.vue‘
import User from ‘../components/User.vue‘
Vue.use(VueRouter)
const routes = [{
path: ‘‘,
redirect: ‘/home‘
},
{
path: ‘/home‘,
component: Home
},
{
path: ‘/about‘,
component: About
},
{
path: ‘/user/:user_id‘,
component: User
}
]
const Home = () => import(‘../components/Home.vue‘)
const About = () => import(‘../components/About.vue‘)
const User = () => import(‘../components/User.vue‘)
Vue.use(VueRouter)
const routes = [{
path: ‘‘,
redirect: ‘/home‘
},
{
path: ‘/home‘,
component: Home
},
{
path: ‘/about‘,
component: About
},
{
path: ‘/user/:user_id‘,
component: User
}
]
<router-view>
{
path: ‘/home‘,
component: Home,
//通过children属性,在home组件中添加两个子组件映射关系
children: [{
path: ‘/home‘,
redirect:‘/home/news‘
},
{
path: ‘news‘,
component: HomeNews
},
{
path: ‘message‘,
component: HomeMessage
}
]
}
//在home组件中使用两个子路由
<div>
<h2>我是Home</h2>
<router-view></router-view>
<p>我是Home内容</p>
<router-link to="/home/news">News</router-link>
<router-link to="/home/message">Message</router-link>
</div>
原文:https://www.cnblogs.com/jincanyu/p/14352309.html