/
index.js
84 lines (74 loc) 路 1.91 KB
/
index.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @author Kuitos
* @since 2019-05-16
*/
import React from 'react';
import ReactDOM from 'react-dom';
// import Vue from 'vue';
import { registerMicroApps, runAfterFirstMounted, setDefaultMountApp, start } from '../../es';
import Framework from './Framework';
// import Framework from './Framework.vue';
// let app = null;
function render({ appContent, loading }) {
/*
examples for vue
*/
// if (!app) {
// app = new Vue({
// el: '#container',
// data() {
// return {
// content: appContent,
// loading,
// };
// },
// render(h) {
// return h(Framework, {
// props: {
// content: this.content,
// loading: this.loading,
// },
// });
// },
// });
// } else {
// app.content = appContent;
// app.loading = loading;
// }
const container = document.getElementById('container');
ReactDOM.render(<Framework loading={loading} content={appContent} />, container);
}
function genActiveRule(routerPrefix) {
return location => location.pathname.startsWith(routerPrefix);
}
function initApp() {
render({ appContent: '', loading: true });
}
initApp();
registerMicroApps(
[
{ name: 'react16-main', entry: '//localhost:7100', render, activeRule: genActiveRule('/react') },
{ name: 'react15 app', entry: '//localhost:7102', render, activeRule: genActiveRule('/15react15') },
{ name: 'vue app', entry: '//localhost:7101', render, activeRule: genActiveRule('/vue') },
],
{
beforeLoad: [
app => {
console.log('before load', app);
},
],
beforeMount: [
app => {
console.log('before mount', app);
},
],
afterUnmount: [
app => {
console.log('after unload', app);
},
],
},
);
setDefaultMountApp('/react');
runAfterFirstMounted(() => console.info('first app mounted'));
start({ prefetch: true });