# 二-signle-spa的使用方式
singleSpa.registerApplication('app1',
async () => {
return {
bootstrap:async()=>{
console.log('应用启动');
},
mount:async()=>{
console.log('应用挂载');
},
unmount:async()=>{
console.log('应用卸载')
}
}
},
location => location.hash.startsWith('#/app1'),
{ store: { name: 'zf' } }
);
singleSpa.start();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 参数分别是:
appName
: 当前注册应用的名字loadApp
: 加载函数(必须返回的是promise),返回的结果必须包含bootstrap
、mount
和unmount
做为接入协议activityWhen
: 满足条件时调用loadApp
方法customProps
:自定义属性可用于父子应用通信
根据使用方式编写源码
const apps = [];
export function registerApplication(appName,loadApp,activeWhen,customProps){
apps.push({
name:appName,
loadApp,
activeWhen,
customProps,
});
}
export function start(){
// todo...
}
export {registerApplication} from './applications/app.js';
export {start} from './start.js';
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14