refactor: refactoring menu generation

This commit is contained in:
vben
2020-11-08 23:13:47 +08:00
parent 90b3fab28e
commit dc42d434f0
11 changed files with 104 additions and 19 deletions

View File

@@ -0,0 +1,4 @@
export default function (id: string) {
const dynamicImportModule: any = id;
return dynamicImportModule;
}

View File

@@ -6,6 +6,8 @@ import { tabStore } from '/@/store/modules/tab';
import { createRouter, createWebHashHistory } from 'vue-router';
import { toRaw } from 'vue';
import { PAGE_LAYOUT_COMPONENT } from '/@/router/constant';
// import { isDevMode } from '/@/utils/env';
import dynamicImport from './dynamicImport';
let currentTo: RouteLocationNormalized | null = null;
@@ -45,12 +47,12 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
// TODO 错误写法
function asyncImportRoute(routes: AppRouteRecordRaw[]) {
routes.forEach((item) => {
let { component } = item;
const { component } = item;
const { children } = item;
if (component) {
component = component.replace(/^\//, '');
item.component = () => import(`/@/views/${component}`);
item.component = dynamicImport(component);
}
children && asyncImportRoute(children);
});
}