fix(plugin-qiankun): 当子应用存在路由而且子应用以路由的形式挂载时,需要在切换路由之前unmount子应用

This commit is contained in:
万纯 2021-03-24 20:27:13 +08:00
parent 444ac52e93
commit 34691cbb89

View File

@ -13,11 +13,20 @@ import { getMasterOptions } from "./masterOptions";
{{#HAS_PLUGIN_MODEL}} {{#HAS_PLUGIN_MODEL}}
import { useModel } from '@@/core/pluginExports'; import { useModel } from '@@/core/pluginExports';
{{/HAS_PLUGIN_MODEL}} {{/HAS_PLUGIN_MODEL}}
import { onBeforeRouteLeave } from "@@/core/coreExports";
function unmountMicroApp(microApp) { let unmountPromise;
if (microApp && microApp.mountPromise) { async function unmountMicroApp(microApp) {
microApp.mountPromise.then(() => microApp.unmount()); if (microApp) {
if (microApp.mountPromise) {
await microApp.mountPromise;
}
if (!unmountPromise) {
unmountPromise = microApp.unmount();
}
return await unmountPromise;
} }
return Promise.resolve();
} }
export const MicroApp = defineComponent({ export const MicroApp = defineComponent({
@ -156,6 +165,10 @@ export const MicroApp = defineComponent({
loadApp(); loadApp();
}); });
onBeforeRouteLeave(async () => {
return await unmountMicroApp(microAppRef.value);
});
watch(()=>{ watch(()=>{
return {...{}, ...propsFromConfigRef.value, ...stateForSlave, ...propsFromParams} return {...{}, ...propsFromConfigRef.value, ...stateForSlave, ...propsFromParams}
}, () => { }, () => {