🐛 manual invoke single-spa start function for parcels and set urlRerouteOnly true as default (#1414)

This commit is contained in:
Kuitos 2021-04-26 14:34:05 +08:00 committed by GitHub
parent acdd5672cf
commit 538869f5b1
2 changed files with 21 additions and 2 deletions

View File

@ -65,7 +65,7 @@
"@babel/runtime": "^7.10.5",
"import-html-entry": "^1.9.0",
"lodash": "^4.17.11",
"single-spa": "5.8.1",
"single-spa": "^5.9.2",
"tslib": "^1.10.0"
},
"devDependencies": {

View File

@ -12,6 +12,10 @@ let microApps: Array<RegistrableApp<Record<string, unknown>>> = [];
// eslint-disable-next-line import/no-mutable-exports
export let frameworkConfiguration: FrameworkConfiguration = {};
let started = false;
const defaultUrlRerouteOnly = true;
const frameworkStartedDefer = new Deferred<void>();
export function registerMicroApps<T extends ObjectType>(
@ -111,12 +115,26 @@ export function loadMicroApp<T extends ObjectType>(
return (await parcelConfigObjectGetterPromise)(container);
};
if (!started) {
// We need to invoke start method of single-spa as the popstate event should be dispatched while the main app calling pushState/replaceState automatically,
// but in single-spa it will check the start status before it dispatch popstate
// see https://github.com/single-spa/single-spa/blob/f28b5963be1484583a072c8145ac0b5a28d91235/src/navigation/navigation-events.js#L101
// ref https://github.com/umijs/qiankun/pull/1071
startSingleSpa({ urlRerouteOnly: frameworkConfiguration.urlRerouteOnly ?? defaultUrlRerouteOnly });
}
return mountRootParcel(memorizedLoadingFn, { domElement: document.createElement('div'), ...props });
}
export function start(opts: FrameworkConfiguration = {}) {
frameworkConfiguration = { prefetch: true, singular: true, sandbox: true, ...opts };
const { prefetch, sandbox, singular, urlRerouteOnly, ...importEntryOpts } = frameworkConfiguration;
const {
prefetch,
sandbox,
singular,
urlRerouteOnly = defaultUrlRerouteOnly,
...importEntryOpts
} = frameworkConfiguration;
if (prefetch) {
doPrefetchStrategy(microApps, prefetch, importEntryOpts);
@ -135,6 +153,7 @@ export function start(opts: FrameworkConfiguration = {}) {
}
startSingleSpa({ urlRerouteOnly });
started = true;
frameworkStartedDefer.resolve();
}