@@ -28,13 +28,16 @@ function ALEPH({ config }: {
28
28
} ) {
29
29
const [ manifest , setManifest ] = useState ( ( ) => config . manifest )
30
30
const [ data , setData ] = useState ( ( ) => config . data )
31
+ const [ e404 , setE404 ] = useState ( ( ) => ( {
32
+ Component : config . E404Component && util . isLikelyReactComponent ( config . E404Component ) ? config . E404Component : E404Page
33
+ } ) )
31
34
const [ app , setApp ] = useState ( ( ) => ( {
32
35
Component : config . AppComponent ? ( util . isLikelyReactComponent ( config . AppComponent ) ? config . AppComponent : E501App ) : null
33
36
} ) )
34
37
const [ pageModules , setPageModules ] = useState ( ( ) => config . pageModules )
35
38
const [ page , setPage ] = useState ( ( ) => ( {
36
39
url : config . url ,
37
- Component : config . PageComponent ? ( util . isLikelyReactComponent ( config . PageComponent ) ? config . PageComponent : E501Page ) : ( config . E404Component || E404Page )
40
+ Component : config . PageComponent ? ( util . isLikelyReactComponent ( config . PageComponent ) ? config . PageComponent : E501Page ) : null
38
41
} ) )
39
42
const onpopstate = useCallback ( async ( ) => {
40
43
const { baseUrl, defaultLocale, locales } = manifest
@@ -58,10 +61,7 @@ function ALEPH({ config }: {
58
61
} )
59
62
}
60
63
} else {
61
- setPage ( {
62
- url,
63
- Component : config . E404Component || E404Page
64
- } )
64
+ setPage ( { url } )
65
65
}
66
66
} , [ manifest , pageModules ] )
67
67
@@ -82,7 +82,14 @@ function ALEPH({ config }: {
82
82
setData ( data )
83
83
}
84
84
const onAddModule = async ( { moduleId, hash } : Module ) => {
85
- if ( moduleId === './app.js' ) {
85
+ if ( moduleId === './404.js' ) {
86
+ const { default : Component } = await import ( getModuleImportUrl ( baseUrl , { moduleId, hash } ) + '?t=' + Date . now ( ) )
87
+ if ( util . isLikelyReactComponent ( Component ) ) {
88
+ setE404 ( { Component } )
89
+ } else {
90
+ setE404 ( { Component : E404Page } )
91
+ }
92
+ } else if ( moduleId === './app.js' ) {
86
93
const { default : Component } = await import ( getModuleImportUrl ( baseUrl , { moduleId, hash } ) + '?t=' + Date . now ( ) )
87
94
if ( util . isLikelyReactComponent ( Component ) ) {
88
95
setApp ( { Component } )
@@ -104,7 +111,9 @@ function ALEPH({ config }: {
104
111
}
105
112
}
106
113
const onRemoveModule = ( moduleId : string ) => {
107
- if ( moduleId === './app.js' ) {
114
+ if ( moduleId === './404.js' ) {
115
+ setE404 ( { Component : E404Page } )
116
+ } else if ( moduleId === './app.js' ) {
108
117
setApp ( { } )
109
118
} else if ( moduleId === './data.js' || moduleId === './data/index.js' ) {
110
119
console . log ( '[DATA]' , { } )
@@ -134,7 +143,7 @@ function ALEPH({ config }: {
134
143
}
135
144
} , [ manifest ] )
136
145
137
- const pageEl = React . createElement ( page . Component )
146
+ const pageEl = React . createElement ( page . Component || e404 . Component )
138
147
return React . createElement (
139
148
AppManifestContext . Provider ,
140
149
{ value : manifest } ,
0 commit comments