重定向也是通过 routes 配置来完成,下面例子是从 /a 重定向到 /b:
const router = new VueRouter({
routes: [
{ path: '/a', redirect: '/b' }
]
})
//router/index.js
const routes = [
{
path: '/films',
name: 'films',
component: Films,
children:[
{
path:'nowPlaying',
component:()=>import('../views/NowPlaying.vue')
},
{
path:'comingSoon',
component:()=>import('../views/ComingSoon.vue')
}
],
redirect:"/films/nowPlaying"
},
]