使用 addRoutes 动态添加路由后 路由跳转 404
代码如下:
this.eventBus.$on('backAdmin', () => {
// 更新路由
this.$router.addRoutes([...adminRouter])
// 跑转路由
this.$router.push({ path: '/home' })
})
通过 addRoutes添加路由后,再调用this.$router.push会跳转404
adminRouter的代码如下:
const routes = [
{
path: '/',
name: 'Home',
redirect: '/about',
component: () => import('@/view/admin/home/home'),
children: [{
name: 'about',
path: '/about',
component: () => import('@/view/admin/home/about'),
}]
},
{
path: '/login',
name: 'login',
component: () => import('@/view/admin/login/login')
},
{
redirect: '/404',
path: '*'
}
]
感谢各位师兄指导下
推荐文章: