路由拦截
...省略生成动态路由...
router.addRoutes(accessRoutes);
if (to.path) {
next({ path: to.path });
} else {
next();
}
} else {
next();
}
跳转404的解决
把404页面放到动态路由的最后
const accessRoutes = await store.dispatch('permission/generateRoutes')
accessRoutes.push({ path: '*', redirect: '/404', hidden: true })
await router.addRoutes(accessRoutes)
// 设置为true,不会留历史记录
next({ ...to, replace: true })