同步6/16
This commit is contained in:
@@ -22,7 +22,18 @@ let isDynamicRoutesAdded = false;
|
||||
const isWhiteList = (path: string) => {
|
||||
return whiteList.some((pattern) => isPathMatch(pattern, path));
|
||||
};
|
||||
|
||||
// ✅ 关键修改:记录当前已添加的动态路由名称列表
|
||||
let currentDynamicRouteNames: string[] = [];
|
||||
// ✅ 关键修改:清除所有已记录的动态路由
|
||||
const removeDynamicRoutes = () => {
|
||||
currentDynamicRouteNames.forEach((name) => {
|
||||
if (name && router.hasRoute(name)) {
|
||||
router.removeRoute(name);
|
||||
}
|
||||
});
|
||||
// 清空记录数组
|
||||
currentDynamicRouteNames = [];
|
||||
};
|
||||
router.beforeEach(async (to, from) => {
|
||||
NProgress.start();
|
||||
|
||||
@@ -46,6 +57,7 @@ router.beforeEach(async (to, from) => {
|
||||
}
|
||||
if (userStore.roles.length === 0) {
|
||||
isRelogin.show = true;
|
||||
removeDynamicRoutes();
|
||||
|
||||
// 获取用户信息
|
||||
const [err, res] = await tos(userStore.getInfo());
|
||||
@@ -60,14 +72,19 @@ router.beforeEach(async (to, from) => {
|
||||
permissionStore.resetRoutes();
|
||||
// 生成动态路由
|
||||
const accessRoutes = await permissionStore.generateRoutes();
|
||||
|
||||
// 添加路由(避免重复添加)
|
||||
accessRoutes.forEach((route) => {
|
||||
if (route.name && router.hasRoute(route.name)) {
|
||||
router.removeRoute(route.name);
|
||||
}
|
||||
if (!isHttp(route.path) && !router.hasRoute(route.name)) {
|
||||
router.addRoute(route);
|
||||
// 记录顶层路由名称
|
||||
if (route.name) {
|
||||
currentDynamicRouteNames.push(route.name as string);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ✅ 标记:路由已添加
|
||||
isDynamicRoutesAdded = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user