Skip to content

Commit

Permalink
perf: router
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Aug 22, 2022
1 parent 5a7187d commit 7c84d9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
8 changes: 0 additions & 8 deletions mock/asyncRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { MockMethod } from "vite-plugin-mock";
// http://mockjs.com/examples.html#Object
const systemRouter = {
path: "/system",
name: "User",
redirect: "/system/user/index",
meta: {
icon: "setting",
title: "menus.hssysManagement",
Expand Down Expand Up @@ -51,8 +49,6 @@ const systemRouter = {

const permissionRouter = {
path: "/permission",
redirect: "/permission/page/index",
name: "PermissionPage",
meta: {
title: "menus.permission",
icon: "lollipop",
Expand All @@ -79,8 +75,6 @@ const permissionRouter = {

const frameRouter = {
path: "/iframe",
name: "FramePure",
redirect: "/iframe/pure",
meta: {
icon: "monitor",
title: "menus.hsExternalPage",
Expand Down Expand Up @@ -115,8 +109,6 @@ const frameRouter = {

const tabsRouter = {
path: "/tabs",
redirect: "/tabs/index",
name: "Tabs",
meta: {
icon: "IF-team-icontabs",
title: "menus.hstabs",
Expand Down
19 changes: 10 additions & 9 deletions src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,16 @@ function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
arrRoutes.forEach((v: RouteRecordRaw) => {
// 将backstage属性加入meta,标识此路由为后端返回路由
v.meta.backstage = true;
if (v.meta?.frameSrc) {
v.component = IFrame;
} else {
// 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会跟path保持一致)
const index = v?.component
? modulesRoutesKeys.findIndex(ev => ev.includes(v.component as any))
: modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
v.component = modulesRoutes[modulesRoutesKeys[index]];
}
// 父级的redirect属性取值:如果子级存在且父级的redirect属性不存在,默认取第一个子级的path;如果子级存在且父级的redirect属性存在,取存在的redirect属性,会覆盖默认值
if (v?.children && !v.redirect) v.redirect = v.children[0].path;
// 父级的name属性取值:如果子级存在且父级的name属性不存在,默认取第一个子级的name;如果子级存在且父级的name属性存在,取存在的name属性,会覆盖默认值
if (v?.children && !v.name) v.name = v.children[0].name;
if (v.meta?.frameSrc) v.component = IFrame;
// 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会跟path保持一致)
const index = v?.component
? modulesRoutesKeys.findIndex(ev => ev.includes(v.component as any))
: modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
v.component = modulesRoutes[modulesRoutesKeys[index]];
if (v.children) {
addAsyncRoutes(v.children);
}
Expand Down

0 comments on commit 7c84d9e

Please sign in to comment.