From 91a0e2fba9fcd0aab8d2de63cb272faa7039f896 Mon Sep 17 00:00:00 2001 From: Haven Date: Tue, 30 Nov 2021 13:58:48 +0800 Subject: [PATCH 1/2] fix: remove extra Slash in microApp base it will generate extra Slash when base is like /xx/ --- .../plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl b/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl index 741bc692..cd1b7776 100644 --- a/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl +++ b/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl @@ -23,6 +23,9 @@ export function getMicroAppRouteComponent(opts: { umiConfigBase = basename === '/' ? '' : basename; {{/runtimeHistory}} + // 去除 base 末尾的 '/' + umiConfigBase = (umiConfigBase.endsWith('/') ? umiConfigBase.substr(0, umiConfigBase.length - 1) : umiConfigBase) + let runtimeMatchedBase = umiConfigBase + (url.endsWith('/') ? url.substr(0, url.length - 1) : url); From 72a9d792c80f8d5aa8a5d30e0abaee64726a1737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=8D=E5=8B=87=E7=BF=94?= Date: Mon, 6 Dec 2021 15:57:22 +0800 Subject: [PATCH 2/2] add removeLastSlash fn --- .../src/master/getMicroAppRouteComponent.ts.tpl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl b/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl index cd1b7776..e7cf5b37 100644 --- a/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl +++ b/packages/plugin-qiankun/src/master/getMicroAppRouteComponent.ts.tpl @@ -15,25 +15,26 @@ export function getMicroAppRouteComponent(opts: { const { url, path } = match; // 默认取静态配置的 base - let umiConfigBase = base === '/' ? '' : base; - + let umiConfigBase = base; {{#runtimeHistory}} // 存在 getCreateHistoryOptions 说明当前应用开启了 runtimeHistory,此时取运行时的 history 配置的 basename const { basename = '/' } = getCreateHistoryOptions(); - umiConfigBase = basename === '/' ? '' : basename; + umiConfigBase = basename; {{/runtimeHistory}} // 去除 base 末尾的 '/' - umiConfigBase = (umiConfigBase.endsWith('/') ? umiConfigBase.substr(0, umiConfigBase.length - 1) : umiConfigBase) - + umiConfigBase = removeLastSlash(umiConfigBase) + let runtimeMatchedBase = - umiConfigBase + (url.endsWith('/') ? url.substr(0, url.length - 1) : url); + umiConfigBase + url; {{#dynamicRoot}} // @see https://github.com/umijs/umi/blob/master/packages/preset-built-in/src/plugins/commands/htmlUtils.ts#L102 runtimeMatchedBase = window.routerBase || location.pathname.split('/').slice(0, -(path.split('/').length - 1)).concat('').join('/'); {{/dynamicRoot}} + runtimeMatchedBase = removeLastSlash(runtimeMatchedBase) + const componentProps = { name: appName, base: runtimeMatchedBase, @@ -45,3 +46,7 @@ export function getMicroAppRouteComponent(opts: { return RouteComponent; } + +export function removeLastSlash(path: string) { + return path.replace(/\/$/g, ''); +}