基本完成v1.0
This commit is contained in:
@@ -13,14 +13,6 @@ const whiteList = ['/login', '/register'];
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start();
|
||||
|
||||
// 修复双斜杠路径问题
|
||||
if (to.path && to.path.includes('//')) {
|
||||
const fixedPath = to.path.replace(/\/+/g, '/');
|
||||
console.warn('检测到双斜杠路径,已修复:', to.path, '->', fixedPath);
|
||||
next({ path: fixedPath, query: to.query, hash: to.hash, replace: true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (getToken()) {
|
||||
if (to.path === '/login') {
|
||||
usePermissionStore().setRoutes([]);
|
||||
@@ -41,6 +33,16 @@ router.beforeEach((to, from, next) => {
|
||||
usePermissionStore()
|
||||
.generateRoutes()
|
||||
.then((accessRoutes) => {
|
||||
// 递归修复所有路由(包括子路由)的双斜杠
|
||||
const fixRouteSlashes = (route) => {
|
||||
if (route.path && route.path.includes('//')) {
|
||||
route.path = route.path.replace(/\/+/g, '/');
|
||||
}
|
||||
if (route.children && Array.isArray(route.children)) {
|
||||
route.children.forEach(child => fixRouteSlashes(child));
|
||||
}
|
||||
};
|
||||
|
||||
// 根据roles权限生成可访问的路由表
|
||||
accessRoutes.forEach((route) => {
|
||||
// 验证路由路径
|
||||
@@ -49,11 +51,8 @@ router.beforeEach((to, from, next) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 修复双斜杠路径
|
||||
if (route.path && route.path.includes('//')) {
|
||||
console.warn('修复路由双斜杠路径:', route.path, '->', route.path.replace(/\/+/g, '/'));
|
||||
route.path = route.path.replace(/\/+/g, '/');
|
||||
}
|
||||
// 递归修复路由及其所有子路由的双斜杠
|
||||
fixRouteSlashes(route);
|
||||
|
||||
router.addRoute(route); // 动态添加可访问路由表
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user