forked from 0x1428571429/microfrontend-submodule-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (45 loc) · 1.43 KB
/
index.js
File metadata and controls
52 lines (45 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react'
import ReactDOM from 'react-dom'
import singleSpaReact from 'single-spa-react'
import registerServiceWorker from './registerServiceWorker'
import RootComponent from './root.component'
import { storeInstance, history } from './Store'
import './index.less'
if (process.env.NODE_ENV === 'development' && !MICRO) {
// 开发环境这样处理
ReactDOM.render(<RootComponent history={history} store={storeInstance} globalEventDistributor={storeInstance} />, document.getElementById('root'))
}
const reactLifecycles = singleSpaReact({
React,
ReactDOM,
rootComponent: (spa) => {
return <RootComponent history={spa.customProps.store.history} store={spa.customProps.store.storeInstance} globalEventDistributor={spa.customProps.globalEventDistributor} />
},
// 可能会有加载顺序的问题
domElementGetter
})
function domElementGetter() {
let el = document.getElementById('sub-module-page')
if (!el) {
el = document.createElement('div')
el.id = 'sub-module-page'
}
let timer = null
timer = setInterval(() => {
if (document.querySelector('.ant-layout-content #sub-module')) {
document.querySelector('.ant-layout-content #sub-module').appendChild(el)
clearInterval(timer)
}
}, 100)
return el
}
export const bootstrap = [
reactLifecycles.bootstrap,
]
export const mount = [
reactLifecycles.mount,
]
export const unmount = [
reactLifecycles.unmount,
]
registerServiceWorker()