mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-02 10:57:24 +08:00
Merge 21e5387ead28f9d5cd1de359877a4c30c430529e into 1730ecf4ce6d7368c03c6c58705758719fc35658
This commit is contained in:
commit
4a87c24acd
@ -7,7 +7,13 @@ import { buildHierarchyTree } from "@/utils/tree";
|
||||
import remainingRouter from "./modules/remaining";
|
||||
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
|
||||
import { usePermissionStoreHook } from "@/store/modules/permission";
|
||||
import { isUrl, openLink, storageLocal, isAllEmpty } from "@pureadmin/utils";
|
||||
import {
|
||||
isUrl,
|
||||
openLink,
|
||||
storageLocal,
|
||||
isAllEmpty,
|
||||
cloneDeep
|
||||
} from "@pureadmin/utils";
|
||||
import {
|
||||
ascending,
|
||||
getTopMenu,
|
||||
@ -55,6 +61,9 @@ export const constantRoutes: Array<RouteRecordRaw> = formatTwoStageRoutes(
|
||||
formatFlatteningRoutes(buildHierarchyTree(ascending(routes.flat(Infinity))))
|
||||
);
|
||||
|
||||
/** 初始的静态路由,用来在退出登陆时重置路由 */
|
||||
const initConstantRoutes: Array<RouteRecordRaw> = cloneDeep(constantRoutes);
|
||||
|
||||
/** 用于渲染菜单,保持原始层级 */
|
||||
export const constantMenus: Array<RouteComponent> = ascending(
|
||||
routes.flat(Infinity)
|
||||
@ -87,17 +96,13 @@ export const router: Router = createRouter({
|
||||
|
||||
/** 重置路由 */
|
||||
export function resetRouter() {
|
||||
router.getRoutes().forEach(route => {
|
||||
const { name, meta } = route;
|
||||
if (name && router.hasRoute(name) && meta?.backstage) {
|
||||
router.removeRoute(name);
|
||||
router.options.routes = formatTwoStageRoutes(
|
||||
formatFlatteningRoutes(
|
||||
buildHierarchyTree(ascending(routes.flat(Infinity)))
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
router.clearRoutes();
|
||||
for (const route of initConstantRoutes.concat(...(remainingRouter as any))) {
|
||||
router.addRoute(route);
|
||||
}
|
||||
router.options.routes = formatTwoStageRoutes(
|
||||
formatFlatteningRoutes(buildHierarchyTree(ascending(routes.flat(Infinity))))
|
||||
);
|
||||
usePermissionStoreHook().clearAllCachePage();
|
||||
}
|
||||
|
||||
|
@ -172,6 +172,8 @@ function handleAsyncRoutes(routeList) {
|
||||
const flattenRouters: any = router
|
||||
.getRoutes()
|
||||
.find(n => n.path === "/");
|
||||
// 保持router.options.routes[0].children与path为"/"的children一致,防止数据不一致导致异常
|
||||
flattenRouters.children = router.options.routes[0].children;
|
||||
router.addRoute(flattenRouters);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user