fix: router

This commit is contained in:
xiaoxian521 2021-12-14 13:42:26 +08:00
parent eeb1d378f2
commit 97388aa47f

View File

@ -2,10 +2,10 @@ import { toRouteType } from "./types";
import { openLink } from "/@/utils/link";
import NProgress from "/@/utils/progress";
import { constantRoutes } from "./modules";
import { split, findIndex } from "lodash-es";
import { transformI18n } from "/@/plugins/i18n";
import remainingRouter from "./modules/remaining";
import { split, find, findIndex } from "lodash-es";
import { storageSession, storageLocal } from "/@/utils/storage";
import { storageSession } from "/@/utils/storage";
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
import { usePermissionStoreHook } from "/@/store/modules/permission";
import { Router, RouteMeta, createRouter, RouteRecordName } from "vue-router";
@ -112,7 +112,7 @@ router.beforeEach((to: toRouteType, _from, next) => {
const route = findRouteByPath(path, routes);
const routePartent = getParentPaths(path, routes);
// 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
if (routePartent.length === 0) {
if (path !== routes[0].path && routePartent.length === 0) {
const { name, meta } = findRouteByPath(
route?.meta?.refreshRedirect,
routes
@ -136,20 +136,6 @@ router.beforeEach((to: toRouteType, _from, next) => {
}
}
router.push(to.fullPath);
// 刷新页面更新标签栏与页面路由匹配
const localRoutes = storageLocal.getItem("responsive-tags");
const home = find(router.options?.routes, route => {
return route.path === "/";
});
const optionsRoutes = [home, ...router.options?.routes[0].children];
const newLocalRoutes = [];
optionsRoutes.forEach(ors => {
localRoutes.forEach(lrs => {
if (ors.path === lrs.parentPath) {
newLocalRoutes.push(lrs);
}
});
});
});
next();
}