diff --git a/src/Umbraco.Web.UI.Client/libs/router/route.context.ts b/src/Umbraco.Web.UI.Client/libs/router/route.context.ts index f4a3caccef..2a3afddfaf 100644 --- a/src/Umbraco.Web.UI.Client/libs/router/route.context.ts +++ b/src/Umbraco.Web.UI.Client/libs/router/route.context.ts @@ -19,6 +19,7 @@ export class UmbRouteContext { #modalContext?: typeof UMB_MODAL_CONTEXT_TOKEN.TYPE; #contextRoutes: UmbRoute[] = []; #routerBasePath?: string; + #routerActiveLocalPath?: string; #activeModalPath?: string; constructor(host: UmbControllerHostElement, mainRouter: IRouterSlot, modalRouter: IRouterSlot) { @@ -94,6 +95,12 @@ export class UmbRouteContext { this.#generateNewUrlBuilders(); } + public _internal_routerGotActiveLocalPath(routerActiveLocalPath: string) { + if (this.#routerActiveLocalPath === routerActiveLocalPath) return; + this.#routerActiveLocalPath = routerActiveLocalPath; + this.#generateNewUrlBuilders(); + } + // Also notice each registration should now hold its handler when its active. public _internal_modalRouterChanged(activeModalPath: string | undefined) { if (this.#activeModalPath === activeModalPath) return; @@ -117,7 +124,12 @@ export class UmbRouteContext { if (!this.#routerBasePath) return; const routeBasePath = this.#routerBasePath.endsWith('/') ? this.#routerBasePath : this.#routerBasePath + '/'; - const localPath = routeBasePath + modalRegistration.generateModalPath(); + const routeActiveLocalPath = this.#routerActiveLocalPath + ? this.#routerActiveLocalPath.endsWith('/') + ? this.#routerActiveLocalPath + : this.#routerActiveLocalPath + '/' + : ''; + const localPath = routeBasePath + routeActiveLocalPath + modalRegistration.generateModalPath(); const urlBuilder = generateRoutePathBuilder(localPath); diff --git a/src/Umbraco.Web.UI.Client/src/shared/router/router-slot.element.ts b/src/Umbraco.Web.UI.Client/src/shared/router/router-slot.element.ts index 1ffb77e243..558d6362ae 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/router/router-slot.element.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/router/router-slot.element.ts @@ -98,6 +98,7 @@ export class UmbRouterSlotElement extends UmbLitElement { const newActiveLocalPath = this.#router.match?.route.path; if (this._activeLocalPath !== newActiveLocalPath) { this._activeLocalPath = newActiveLocalPath; + this.#routeContext._internal_routerGotActiveLocalPath(this._activeLocalPath); this.dispatchEvent(new UmbRouterSlotChangeEvent()); } } @@ -106,6 +107,7 @@ export class UmbRouterSlotElement extends UmbLitElement { private _onNavigationChanged = (event?: any) => { if (event.detail.slot === this.#router) { this._activeLocalPath = event.detail.match.route.path; + this.#routeContext._internal_routerGotActiveLocalPath(this._activeLocalPath); this.dispatchEvent(new UmbRouterSlotChangeEvent()); } else if (event.detail.slot === this.#modalRouter) { const newActiveModalLocalPath = event.detail.match.route.path;