1
- import { isLowCodeComponentSchema } from '@alilc/lowcode-shared' ;
2
1
import { useRenderContext } from '../context/render' ;
3
- import { createComponentBySchema , ReactComponent } from '../runtime' ;
2
+ import { getComponentByName } from '../runtime' ;
4
3
import Route from './route' ;
5
4
import { rendererExtends } from '../plugin' ;
6
5
7
6
export default function App ( ) {
8
- const { schema, packageManager } = useRenderContext ( ) ;
7
+ const renderContext = useRenderContext ( ) ;
8
+ const { schema } = renderContext ;
9
9
const appWrappers = rendererExtends . getAppWrappers ( ) ;
10
10
const wrappers = rendererExtends . getRouteWrappers ( ) ;
11
11
12
- function getLayoutComponent ( ) {
13
- const config = schema . get ( 'config' ) ;
14
- const componentName = config ?. layout ?. componentName as string ;
15
-
16
- if ( componentName ) {
17
- const Component = packageManager . getComponent < ReactComponent > ( componentName ) ;
18
-
19
- if ( isLowCodeComponentSchema ( Component ) ) {
20
- return createComponentBySchema ( Component . schema , {
21
- displayName : componentName ,
22
- } ) ;
23
- }
24
-
25
- return Component ;
26
- }
27
- }
28
-
29
- const Layout = getLayoutComponent ( ) ;
30
-
31
12
let element = < Route /> ;
32
13
33
14
if ( wrappers . length > 0 ) {
@@ -36,9 +17,16 @@ export default function App() {
36
17
} , element ) ;
37
18
}
38
19
39
- if ( Layout ) {
40
- const layoutProps : any = schema . get ( 'config' ) ?. layout ?. props ?? { } ;
41
- element = < Layout { ...layoutProps } > { element } </ Layout > ;
20
+ const layoutConfig = schema . get ( 'config' ) ?. layout ;
21
+
22
+ if ( layoutConfig ) {
23
+ const componentName = layoutConfig . componentName as string ;
24
+ const Layout = getComponentByName ( componentName , renderContext ) ;
25
+
26
+ if ( Layout ) {
27
+ const layoutProps : any = layoutConfig . props ?? { } ;
28
+ element = < Layout { ...layoutProps } > { element } </ Layout > ;
29
+ }
42
30
}
43
31
44
32
if ( appWrappers . length > 0 ) {
0 commit comments