mirror of https://gitee.com/answerdev/answer.git
fix(router): remove unnecessary lazy route component
This commit is contained in:
parent
eb2efc365c
commit
ce089fdb32
|
@ -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[] = [];
|
||||
|
|
Loading…
Reference in New Issue