function patchedUpdateState(updateState, methodName) {
return function () {
var urlBefore = window.location.href;
var result = updateState.apply(this, arguments);
var urlAfter = window.location.href;
if (!urlRerouteOnly || urlBefore !== urlAfter) {
if (isStarted()) {
// fire an artificial popstate event once single-spa is started,
// so that single-spa applications know about routing that
// occurs in a different application
window.dispatchEvent(createPopStateEvent(window.history.state, methodName));
} else {
// do not fire an artificial popstate event before single-spa is started,
// since no single-spa applications need to know about routing events
// outside of their own router.
reroute([]);
}
}
return result;
What happens?
使用qiankun后路由跳转会立即触发页面的react-router 的history.block
Mini Showcase Repository(REQUIRED)
因为single-spa的popstate触发机制,导致history.pushState跳转路由时触发popstate,从而触发history.block
function patchedUpdateState(updateState, methodName) { return function () { var urlBefore = window.location.href; var result = updateState.apply(this, arguments); var urlAfter = window.location.href;
}; }
How To Reproduce
Steps to reproduce the behavior: 1. 2.
Expected behavior 1. 2.
Context