@@ -11,62 +11,61 @@ import routeList from './route-config'
11
11
import matchRoute from '../../common/match-route'
12
12
// @ts -ignore
13
13
import proConfig from '../../common/pro-config'
14
- // @ts -ignore
14
+ // @ts -ignore
15
15
import StyleContext from 'isomorphic-style-loader/StyleContext'
16
16
17
17
function renderDom ( routeList : any ) {
18
- // @ts -ignore
19
- const insertCss = ( ...styles ) => {
20
- const removeCss = styles . map ( style => style . _insertCss ( ) ) ; //客户端执行,插入style
21
- return ( ) => removeCss . forEach ( dispose => dispose ( ) ) ; //组件卸载时 移除当前的 style 标签
22
- }
23
- console . log ( '渲染index' )
24
- // 渲染index
25
- // @ts -ignore
26
- const renderMethod = module . hot ? ReactDOM . render : ReactDOM . hydrate ;
27
- console . log ( 'routeList===>' , routeList )
28
- renderMethod (
29
- < BrowserRouter >
30
- < StyleContext . Provider value = { { insertCss } } >
31
- < App routeList = { routeList } /> </ StyleContext . Provider >
32
- </ BrowserRouter > ,
33
- document . getElementById ( 'app' ) ,
34
- )
18
+ // @ts -ignore
19
+ const insertCss = ( ...styles ) => {
20
+ const removeCss = styles . map ( style => style . _insertCss ( ) ) // 客户端执行,插入style
21
+ return ( ) => removeCss . forEach ( dispose => dispose ( ) ) // 组件卸载时 移除当前的 style 标签
22
+ }
23
+ console . log ( '渲染index' )
24
+ // 渲染index
25
+ // @ts -ignore
26
+ const renderMethod = module . hot ? ReactDOM . render : ReactDOM . hydrate
27
+ console . log ( 'routeList===>' , routeList )
28
+ renderMethod (
29
+ < BrowserRouter >
30
+ < StyleContext . Provider value = { { insertCss } } >
31
+ < App routeList = { routeList } />
32
+ </ StyleContext . Provider >
33
+ </ BrowserRouter > ,
34
+ document . getElementById ( 'app' )
35
+ )
35
36
}
36
37
37
38
function clientRender ( routeList : any ) {
39
+ if ( document . getElementById ( 'ssrTextInitData' ) ) {
40
+ // @ts -ignore
41
+ let value = document . getElementById ( 'ssrTextInitData' ) . value
42
+ let initialData = JSON . parse ( value && value . replace ( / \\ n / g, '' ) )
43
+ // @ts -ignore
44
+ window . __INITIAL_DATA__ = initialData || { }
45
+ }
38
46
39
- if ( document . getElementById ( 'ssrTextInitData' ) ) {
40
- // @ts -ignore
41
- let value = document . getElementById ( 'ssrTextInitData' ) . value
42
- let initialData = JSON . parse ( value && value . replace ( / \\ n / g, '' ) )
43
- // @ts -ignore
44
- window . __INITIAL_DATA__ = initialData || { }
45
- }
46
-
47
-
48
- //查找路由
49
- let matchResult = matchRoute ( document . location . pathname , routeList )
50
- console . log ( 'matchResult' , matchResult )
51
- let { targetRoute } = matchResult
52
- console . log ( 'targetRoute===>' , targetRoute )
53
- if ( targetRoute ) {
54
- //预加载 等待异步脚本加载完成
55
- // if (targetRoute.component[proConfig.asyncComponentKey]) {
56
- // targetRoute
57
- // .component()
58
- // .then((res: any) => {
59
- // //异步组件加载完成后再渲染页面
60
- // console.log('异步组件加载完成.')
61
- //设置已加载完的组件,否则需要重新请求
62
- // targetRoute.component = res ? res.default : null
63
- renderDom ( routeList )
64
- // })
65
- // }
66
- } else {
67
- console . log ( 'renderDom==>' , renderDom )
68
- renderDom ( routeList )
69
- }
47
+ //查找路由
48
+ let matchResult = matchRoute ( document . location . pathname , routeList )
49
+ console . log ( 'matchResult' , matchResult )
50
+ let { targetRoute } = matchResult
51
+ console . log ( 'targetRoute===>' , targetRoute )
52
+ if ( targetRoute ) {
53
+ //预加载 等待异步脚本加载完成
54
+ // if (targetRoute.component[proConfig.asyncComponentKey]) {
55
+ // targetRoute
56
+ // .component()
57
+ // .then((res: any) => {
58
+ // //异步组件加载完成后再渲染页面
59
+ // console.log('异步组件加载完成.')
60
+ //设置已加载完的组件,否则需要重新请求
61
+ // targetRoute.component = res ? res.default : null
62
+ renderDom ( routeList )
63
+ // })
64
+ // }
65
+ } else {
66
+ console . log ( 'renderDom==>' , renderDom )
67
+ renderDom ( routeList )
68
+ }
70
69
}
71
70
72
71
//渲染入口
@@ -75,6 +74,6 @@ clientRender(routeList)
75
74
//开发环境才会开启
76
75
// @ts -ignore
77
76
if ( process . env . NODE_ENV === 'development' && module . hot ) {
78
- // @ts -ignore
79
- module . hot . accept ( )
77
+ // @ts -ignore
78
+ module . hot . accept ( )
80
79
}
0 commit comments