Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions libs/mf-tools/src/lib/web-components/bootstrap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
PlatformRef,
Type,
Version,
VERSION,
} from '@angular/core';
import { platformBrowser } from '@angular/platform-browser';
import { VERSION } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import {
getGlobalStateSlice,
setGlobalStateSlice,
Expand Down Expand Up @@ -211,12 +212,13 @@ function shareShellZone(injector: Injector) {

function connectMicroFrontendRouter(injector: Injector) {
const router = injector.get(Router);
const baseHref = injector.get(APP_BASE_HREF, '');
const useHash = location.href.includes('#');

if (!router) {
console.warn('No router to connect found');
return;
}

connectRouter(router, useHash);
connectRouter(router, useHash, baseHref);
}
9 changes: 8 additions & 1 deletion libs/mf-tools/src/lib/web-components/router-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ export function endsWith(prefix: string): UrlMatcher {
};
}

export function connectRouter(router: Router, useHash = false): void {
export function connectRouter(
router: Router,
useHash = false,
baseHref?: string
): void {
let url: string;
if (!useHash) {
url = `${location.pathname.substring(1)}${location.search}`;
if (baseHref && url.startsWith(baseHref)) {
url = url.replace(baseHref, '');
}
router.navigateByUrl(url);
window.addEventListener('popstate', () => {
router.navigateByUrl(url);
Expand Down