Description
I am have problems getting the browser back and forward button working in and MFE. I think there is a bug in the
following function in this file:
export function connectRouter(router: Router, useHash = false): void {
let url: string;
if (!useHash) {
url = ${location.pathname.substring(1)}${location.search}
;
router.navigateByUrl(url);
window.addEventListener('popstate', () => {
router.navigateByUrl(url);
});
} else {
url = ${location.hash.substring(1)}${location.search}
;
router.navigateByUrl(url);
window.addEventListener('hashchange', () => {
router.navigateByUrl(url);
});
}
}
When I change it to this:
export function connectRouter(router: Router, useHash = false): void {
let url: string;
if (!useHash) {
url = `${location.pathname.substring(1)}${location.search}`;
router.navigateByUrl(url);
window.addEventListener('popstate', () => {
url = `${location.hash.substring(1)}${location.search}`;
router.navigateByUrl(url);
});
}
else {
url = `${location.hash.substring(1)}${location.search}`;
router.navigateByUrl(url);
window.addEventListener('hashchange', () => {
url = `${location.hash.substring(1)}${location.search}`;
router.navigateByUrl(url);
});
}
}
Subtle change but url should be recalculated in the addEventListener.
I think this change would better match with the code in the article:
https://www.angulararchitects.io/en/blog/multi-framework-and-version-micro-frontends-with-module-federation-the-good-the-bad-the-ugly/ under the section "Several Routers must Work Together"