fix modals to extend local route

This commit is contained in:
Niels Lyngsø
2023-05-21 20:50:21 +02:00
parent 5e469fd205
commit d954a01c9c
2 changed files with 15 additions and 1 deletions

View File

@@ -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);

View File

@@ -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;