1
- import loadable from "@loadable/component " ;
1
+ import { lazy } from "react " ;
2
2
3
3
import { Layout } from "components/Layout" ;
4
4
import { UI } from "components/UI" ;
@@ -9,33 +9,36 @@ import { filter } from "./tools";
9
9
10
10
import type { PreLoadRouteConfig } from "types/router" ;
11
11
12
- const LoadAble_I18n = loadable ( ( ) => import ( "../components/i18n" ) ) ;
13
-
14
12
const baseRouter : PreLoadRouteConfig = {
15
13
element : < Layout /> ,
16
- Component : Layout ,
17
14
} ;
18
15
19
- const LoadAble_UI = loadable ( ( ) => import ( "../components/chakraComponent" ) ) ;
20
-
21
- const routes : PreLoadRouteConfig [ ] = [
22
- { path : "/" , element : < UI /> , Component : UI } ,
23
- {
24
- path : "/i18n" ,
25
- element : < LoadAble_I18n /> ,
26
- Component : LoadAble_I18n ,
27
- } ,
28
- { path : "/chakra" , element : < LoadAble_UI /> , Component : LoadAble_UI } ,
29
- ] ;
16
+ const routes : PreLoadRouteConfig [ ] = [ { path : "/" , element : < UI /> } ] ;
30
17
31
18
const dynamicRoutes = dynamicRouteConfig
32
19
. map ( ( it ) => ( {
33
20
path : it . componentPath === "404" ? "/*" : it . path ,
34
- component : loadable ( ( ) => import ( `../pages/${ it . componentPath } ` ) , {
35
- resolveComponent : ( module ) => AutoInjectInitialProps ( module . default ) ,
36
- } ) ,
21
+ preLoad : ( ) =>
22
+ import (
23
+ /* webpackMode: "lazy" */
24
+ /* webpackPrefetch: true */
25
+ /* webpackPreload: true */
26
+ /* webpackChunkName: "[request]" */
27
+ `../pages/${ it . componentPath } `
28
+ ) ,
29
+ component : lazy ( ( ) =>
30
+ import (
31
+ /* webpackMode: "lazy" */
32
+ /* webpackPrefetch: true */
33
+ /* webpackPreload: true */
34
+ /* webpackChunkName: "[request]" */
35
+ `../pages/${ it . componentPath } `
36
+ ) . then ( ( module ) => ( {
37
+ default : AutoInjectInitialProps ( module . default ) ,
38
+ } ) )
39
+ ) ,
37
40
} ) )
38
- . map ( ( { path, component : Component } ) => ( { path : path , Component , element : < Component /> } ) ) ;
41
+ . map ( ( { path, component : Component , preLoad } ) => ( { path : path , preLoad , element : < Component /> } ) ) ;
39
42
40
43
baseRouter . children = filter ( routes . concat ( dynamicRoutes ) || [ ] )
41
44
. sort ( ( a ) => ( a . path === "/*" ? 1 : 0 ) )
0 commit comments