From ffc88ab656395638fd172237f35db8581eaae628 Mon Sep 17 00:00:00 2001 From: harrywan Date: Mon, 19 Apr 2021 20:04:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(qiankun):=20=E6=94=AF=E6=8C=81memoryHistor?= =?UTF-8?q?y=E6=A8=A1=E5=BC=8F,=E5=B5=8C=E5=A5=97=E5=AD=90=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E4=BB=BB=E6=84=8F=E8=B7=AF=E7=94=B1=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/micro/runtime/lifecycles.tpl | 9 +++------ .../src/plugins/misc/route/index.js | 2 +- .../src/plugins/misc/route/template/routes.tpl | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl b/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl index d1a99206..807ce787 100644 --- a/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl +++ b/packages/fes-plugin-qiankun/src/micro/runtime/lifecycles.tpl @@ -1,4 +1,4 @@ -import { plugin, ApplyPluginsType, getRouter, getHistory } from '@@/core/coreExports'; +import { plugin, ApplyPluginsType, getRouter, getHistory, destroyRouter } from '@@/core/coreExports'; {{#HAS_PLUGIN_MODEL}} import { setModelState } from './qiankunModel'; {{/HAS_PLUGIN_MODEL}} @@ -74,14 +74,10 @@ export function genMount(mountElementId) { clientRenderOptsStack.push(clientRenderOpts); if(props.url){ - history.url = props.url; + history.url = props.url || '/'; } if(props.onRouterInit){ history.onRouterInit = props.onRouterInit; - const router = getRouter(); - if(router){ - history.onRouterInit(router); - } } // 第一次 mount 会自动触发 render,非第一次 mount 则需手动触发 @@ -118,6 +114,7 @@ export function genUnmount() { const app = await cacheAppPromise; app.unmount(); } + destroyRouter(); const slaveRuntime = getSlaveRuntime(); if (slaveRuntime.unmount) { await slaveRuntime.unmount(props); diff --git a/packages/fes-preset-built-in/src/plugins/misc/route/index.js b/packages/fes-preset-built-in/src/plugins/misc/route/index.js index 5debe708..37ac9a22 100644 --- a/packages/fes-preset-built-in/src/plugins/misc/route/index.js +++ b/packages/fes-preset-built-in/src/plugins/misc/route/index.js @@ -293,7 +293,7 @@ export default function (api) { api.addCoreExports(() => [ { - specifiers: ['getRoutes', 'getRouter', 'getHistory'], + specifiers: ['getRoutes', 'getRouter', 'getHistory', 'destroyRouter'], source: absCoreFilePath } ]); diff --git a/packages/fes-preset-built-in/src/plugins/misc/route/template/routes.tpl b/packages/fes-preset-built-in/src/plugins/misc/route/template/routes.tpl index ceaff8fa..3e134cd6 100644 --- a/packages/fes-preset-built-in/src/plugins/misc/route/template/routes.tpl +++ b/packages/fes-preset-built-in/src/plugins/misc/route/template/routes.tpl @@ -40,9 +40,20 @@ export const createRouter = () => { }; export const getRouter = ()=>{ - return router; + if(!router){ + console.warn(`[preset-build-in] router is null`) + } + return router; } export const getHistory = ()=>{ - return history; + if(!history){ + console.warn(`[preset-build-in] history is null`) + } + return history; +} + +export const destroyRouter = ()=>{ + router = null; + history = null; }