Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-qiankun): remove extra Slash in microApp base #753

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +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 = 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,
Expand All @@ -42,3 +46,7 @@ export function getMicroAppRouteComponent(opts: {

return RouteComponent;
}

export function removeLastSlash(path: string) {
return path.replace(/\/$/g, '');
}