diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js index c6b136c4aa7d5b4eb62cb5fb137e9a43683f3573..616079c7ee318f3fbcf1fc1800e3b120df97dda3 100644 --- a/packages/app-shell/src/app-shell.js +++ b/packages/app-shell/src/app-shell.js @@ -219,10 +219,11 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) { this.router = new Router(routes, { routeName: 'mainRoute', getState: () => { - return { + let state = { component: this.activeView, lang: this.lang, }; + return state; }, setState: (state) => { this.updateLangIfChanged(state.lang); diff --git a/packages/app-shell/src/router.js b/packages/app-shell/src/router.js index c05b899c25235e66d9e50f3231fdbcf62cf7daab..8970e1758000bf4a85759939d2b064318d315a9b 100644 --- a/packages/app-shell/src/router.js +++ b/packages/app-shell/src/router.js @@ -44,9 +44,7 @@ export class Router { // In case of a router redirect, set the new location if (newPathname !== oldPathName) { const referrerUrl = location.href; - if (!newPathname.endsWith('/root')) { - window.history.replaceState({}, '', newPathname); - } + window.history.replaceState({}, '', newPathname); this.dispatchLocationChanged(referrerUrl); } this.setState(page); @@ -68,9 +66,7 @@ export class Router { if (newPathname === oldPathname) return; const referrerUrl = location.href; - if (!newPathname.endsWith('/root')) { - window.history.pushState({}, '', newPathname); - } + window.history.pushState({}, '', newPathname); this.dispatchLocationChanged(referrerUrl); }); } @@ -107,12 +103,12 @@ export class Router { partialState = {}; let combined = {...currentState, ...partialState}; - // prevent: Uncaught TypeError: Expected "component" to match "[^\/#\?]+?", but got "" - if (combined.component === '') { - combined.component = 'root'; + try { + return generateUrls(this.router)(this.routeName, combined); + } catch { + // XXX: In case we have partial state this will fail, just return the old path + return location.pathname; } - - return generateUrls(this.router)(this.routeName, combined); } dispatchLocationChanged(referrerUrl = "") {