Vue-Router 权限路由控制
问题: 项目使用 addRoutes() 控制路由权限导致警告 Duplicate named routes definition
解决方式: 修改 router.matcher, 达到重置 routes 的效果,再使用 addRoutes
// 定义一个函数来创建router
export const createRouter = routes => new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
});
// 在使用addRoutes的地方
// 重置当前router的matcher = 初始router.matcher
router.matcher = createRouter(constantRoutes).matcher;
router.addRoutes(routes);