路由修改

pull/1/head
zhangqihang 2024-02-05 14:18:39 +08:00
parent aefcd3d4e3
commit 065523c0aa
1 changed files with 5 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import { cloneDeep } from "lodash-es";
import pinia from "./pinia"; import pinia from "./pinia";
import children from "@/components/children/index"; import children from "@/components/children/index";
import { MODEL } from "@/assets/js/constant"; import { MODEL } from "@/assets/js/constant";
import asyncRouter from "@/assets/js/asyncRouter"; // import asyncRouter from "@/assets/js/asyncRouter";
import { getAsyncRouter } from "@/request/api"; import { getAsyncRouter } from "@/request/api";
// import { getRouteTreeAll } from "@/request/system_management.js"; // import { getRouteTreeAll } from "@/request/system_management.js";
@ -30,10 +30,10 @@ router.beforeEach(async (to, from, next) => {
// 变量里没有储存路由 // 变量里没有储存路由
// pinia里没有储存路由去后台获取路由 // pinia里没有储存路由去后台获取路由
if (routerStore.getRouters.length === 0) { if (routerStore.getRouters.length === 0) {
await getAsyncRouter(); const resData = await getAsyncRouter();
// const resData = await getRouteTreeAll(); // const resData = await getRouteTreeAll();
// storageRouter = resData.menuList; // 后台请求得到的路由数据 storageRouter = resData.routeList; // 后台请求得到的路由数据
storageRouter = asyncRouter; // 死路由 // storageRouter = asyncRouter; // 死路由
routerStore.setRouters(storageRouter); // 存储路由 routerStore.setRouters(storageRouter); // 存储路由
routerGo(to, next); // 执行路由跳转方法 routerGo(to, next); // 执行路由跳转方法
} else { } else {
@ -76,6 +76,7 @@ function routerGo(to, next) {
function filterAsyncRouter(asyncRouterMap) { function filterAsyncRouter(asyncRouterMap) {
// 遍历后台传来的路由字符串,转换为组件对象 // 遍历后台传来的路由字符串,转换为组件对象
return asyncRouterMap.filter((route) => { return asyncRouterMap.filter((route) => {
route.meta = JSON.parse(route.meta);
if (route.component) { if (route.component) {
if (route.component === "children") { if (route.component === "children") {
route.component = children; route.component = children;