From 4fbe27879940cf7d075cf23cff72acba05cfd634 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 23 Aug 2022 15:17:13 +0200 Subject: [PATCH] app-shell: preserve the "extra" path components when changing the routing state In case the current language changes or the current activity is re-selected in the menu we don't want to lose the extra trailing path components. --- packages/app-shell/src/app-shell.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js index 0c7d2a88..4af68486 100644 --- a/packages/app-shell/src/app-shell.js +++ b/packages/app-shell/src/app-shell.js @@ -200,10 +200,10 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) { }, { name: 'mainRoute', - path: ['/:component', '/:component/(.*)'], + path: ['/:component/:extra*'], action: (context, params) => { let componentTag = params.component.toLowerCase(); - let extra = params[0] ? params[0].split('/') : []; + let extra = params.extra ?? []; return { lang: params.lang, component: componentTag, @@ -958,12 +958,19 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) { // build the menu let menuTemplates = []; for (let routingName of this.visibleRoutes) { + let partialState = { + component: routingName, + }; + // clear the extra state for everything but the current activity + if (this.activeView !== routingName) { + partialState['extra'] = []; + } menuTemplates.push( html` <li> <a @click="${(e) => this.onMenuItemClick(e)}" - href="${this.router.getPathname({component: routingName})}" + href="${this.router.getPathname(partialState)}" data-nav class="${getSelectClasses(routingName)}" title="${this.metaDataText(routingName, 'description')}"> -- GitLab