fix: 修复路由showlinkfalse的异步路由,刷新后不显示

This commit is contained in:
xiaoxian521 2022-07-18 13:48:59 +08:00
parent b2dd962161
commit 4c6acc91ab

View File

@ -8,6 +8,7 @@ import {
} from "vue-router"; } from "vue-router";
import { router } from "./index"; import { router } from "./index";
import { loadEnv } from "../../build"; import { loadEnv } from "../../build";
import { cloneDeep } from "lodash-unified";
import { useTimeoutFn } from "@vueuse/core"; import { useTimeoutFn } from "@vueuse/core";
import { RouteConfigs } from "/@/layout/types"; import { RouteConfigs } from "/@/layout/types";
import { buildHierarchyTree } from "@pureadmin/utils"; import { buildHierarchyTree } from "@pureadmin/utils";
@ -39,7 +40,7 @@ function ascending(arr: any[]) {
// 过滤meta中showLink为false的路由 // 过滤meta中showLink为false的路由
function filterTree(data: RouteComponent[]) { function filterTree(data: RouteComponent[]) {
const newTree = data.filter( const newTree = cloneDeep(data).filter(
(v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false (v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false
); );
newTree.forEach( newTree.forEach(
@ -135,7 +136,7 @@ function initRouter(name: string) {
// 最终路由进行升序 // 最终路由进行升序
ascending(router.options.routes[0].children); ascending(router.options.routes[0].children);
if (!router.hasRoute(v?.name)) router.addRoute(v); if (!router.hasRoute(v?.name)) router.addRoute(v);
const flattenRouters = router const flattenRouters: any = router
.getRoutes() .getRoutes()
.find(n => n.path === "/"); .find(n => n.path === "/");
router.addRoute(flattenRouters); router.addRoute(flattenRouters);