fix(router): remove unnecessary lazy route component

This commit is contained in:
haitao(lj) 2022-10-18 17:32:21 +08:00
parent eb2efc365c
commit ce089fdb32
1 changed files with 17 additions and 11 deletions

View File

@ -1,6 +1,8 @@
import React, { Suspense, lazy } from 'react';
import { RouteObject, createBrowserRouter } from 'react-router-dom';
import Layout from '@answer/pages/Layout';
import routeConfig, { RouteNode } from '@/router/route-config';
import RouteRules from '@/router/route-rules';
@ -8,17 +10,21 @@ const routes: RouteObject[] = [];
const routeGen = (routeNodes: RouteNode[], root: RouteObject[]) => {
routeNodes.forEach((rn) => {
rn.page = rn.page.replace('pages/', '');
if (rn.path === '/') {
rn.element = <Layout />;
} else {
/**
* cannot use a fully dynamic import statement
* ref: https://webpack.js.org/api/module-methods/#import-1
*/
rn.page = rn.page.replace('pages/', '');
const Control = lazy(() => import(`@/pages/${rn.page}`));
rn.element = (
<Suspense>
<Control />
</Suspense>
);
}
root.push(rn);
if (Array.isArray(rn.rules)) {
const ruleFunc: Function[] = [];