From 34691cbb894472e7da9564e8024261714531129d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E7=BA=AF?= Date: Wed, 24 Mar 2021 20:27:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(plugin-qiankun):=20=20=E5=BD=93=E5=AD=90?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=AD=98=E5=9C=A8=E8=B7=AF=E7=94=B1=E8=80=8C?= =?UTF-8?q?=E4=B8=94=E5=AD=90=E5=BA=94=E7=94=A8=E4=BB=A5=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=9A=84=E5=BD=A2=E5=BC=8F=E6=8C=82=E8=BD=BD=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=9C=A8=E5=88=87=E6=8D=A2=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E4=B9=8B=E5=89=8Dunmount=E5=AD=90=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/runtime/MicroApp.tpl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl b/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl index 45514077..c4804697 100644 --- a/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl +++ b/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl @@ -13,11 +13,20 @@ import { getMasterOptions } from "./masterOptions"; {{#HAS_PLUGIN_MODEL}} import { useModel } from '@@/core/pluginExports'; {{/HAS_PLUGIN_MODEL}} +import { onBeforeRouteLeave } from "@@/core/coreExports"; -function unmountMicroApp(microApp) { - if (microApp && microApp.mountPromise) { - microApp.mountPromise.then(() => microApp.unmount()); +let unmountPromise; +async function unmountMicroApp(microApp) { + if (microApp) { + if (microApp.mountPromise) { + await microApp.mountPromise; + } + if (!unmountPromise) { + unmountPromise = microApp.unmount(); + } + return await unmountPromise; } + return Promise.resolve(); } export const MicroApp = defineComponent({ @@ -156,6 +165,10 @@ export const MicroApp = defineComponent({ loadApp(); }); + onBeforeRouteLeave(async () => { + return await unmountMicroApp(microAppRef.value); + }); + watch(()=>{ return {...{}, ...propsFromConfigRef.value, ...stateForSlave, ...propsFromParams} }, () => {