物联网问题解决,只差最后测试完善
This commit is contained in:
@@ -12,6 +12,15 @@ 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([]);
|
||||
@@ -34,6 +43,18 @@ router.beforeEach((to, from, next) => {
|
||||
.then((accessRoutes) => {
|
||||
// 根据roles权限生成可访问的路由表
|
||||
accessRoutes.forEach((route) => {
|
||||
// 验证路由路径
|
||||
if (!route.path || !route.path.startsWith('/')) {
|
||||
console.error('Invalid route path:', route.path, 'for route:', route);
|
||||
return;
|
||||
}
|
||||
|
||||
// 修复双斜杠路径
|
||||
if (route.path && route.path.includes('//')) {
|
||||
console.warn('修复路由双斜杠路径:', route.path, '->', route.path.replace(/\/+/g, '/'));
|
||||
route.path = route.path.replace(/\/+/g, '/');
|
||||
}
|
||||
|
||||
router.addRoute(route); // 动态添加可访问路由表
|
||||
});
|
||||
next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
|
||||
|
||||
Reference in New Issue
Block a user