报错提示
路由命名重复定义
原因
项目中需要用到addroute
router.beforeEach((to, from, next) => {
if (true) { //根据权限添加路由
router.addRoute({
path: '/tree',
name: 'tree',
component: () => import('../views/example/tree.vue')
})
next({ ...to, replace: true })
// next()
}else {
}
next()
})
第一次经过beforeEach时添加了一次路由,接着next()时又进入到beforeEach再添加一次路由导致重复定义。
解决办法
我的解决办法是不在beforeEach中添加权限路由,直接在main.js或者App.vue中调用一次路由。