vue.js 每次使用router.addRoutes 报错TypeError: routes.forEach is not a function 什么情况 5C

```router.beforeEach((to, from, next) => {
if (to.path.startsWith('/login')) {
window.localStorage.removeItem('access-user')
next()
} else {
let user = localStorage.getItem('access-user')
if (!user) {
next({path: '/login'})
} else {
next()
}
}
})
let route = {
routes: [{
path: '/MenuGroup',
component: (resolve) => require(['../components/Home'], resolve)
}]
}
router.addRoutes(route)
export default router

2个回答

let route = [{
path: '/MenuGroup',
component: (resolve) => require(['../components/Home'], resolve)
}]
router.addRoutes(route);

router.addRoutes动态添加更多的路由规则。参数必须是一个符合 routes 选项要求的数组

1、console.log(router)看看有没有addRoutes那个函数
2、一般使用需要import

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐