Skip to content
Snippets Groups Projects
Commit e99096a9 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Clean up initial router handling

If the current state can't be used to generate a path just fall back
to the current path
parent 0dcdc161
No related branches found
No related tags found
1 merge request!65Clean up initial router handling and add a default state
...@@ -219,10 +219,11 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) { ...@@ -219,10 +219,11 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
this.router = new Router(routes, { this.router = new Router(routes, {
routeName: 'mainRoute', routeName: 'mainRoute',
getState: () => { getState: () => {
return { let state = {
component: this.activeView, component: this.activeView,
lang: this.lang, lang: this.lang,
}; };
return state;
}, },
setState: (state) => { setState: (state) => {
this.updateLangIfChanged(state.lang); this.updateLangIfChanged(state.lang);
......
...@@ -44,9 +44,7 @@ export class Router { ...@@ -44,9 +44,7 @@ export class Router {
// In case of a router redirect, set the new location // In case of a router redirect, set the new location
if (newPathname !== oldPathName) { if (newPathname !== oldPathName) {
const referrerUrl = location.href; const referrerUrl = location.href;
if (!newPathname.endsWith('/root')) { window.history.replaceState({}, '', newPathname);
window.history.replaceState({}, '', newPathname);
}
this.dispatchLocationChanged(referrerUrl); this.dispatchLocationChanged(referrerUrl);
} }
this.setState(page); this.setState(page);
...@@ -68,9 +66,7 @@ export class Router { ...@@ -68,9 +66,7 @@ export class Router {
if (newPathname === oldPathname) if (newPathname === oldPathname)
return; return;
const referrerUrl = location.href; const referrerUrl = location.href;
if (!newPathname.endsWith('/root')) { window.history.pushState({}, '', newPathname);
window.history.pushState({}, '', newPathname);
}
this.dispatchLocationChanged(referrerUrl); this.dispatchLocationChanged(referrerUrl);
}); });
} }
...@@ -107,12 +103,12 @@ export class Router { ...@@ -107,12 +103,12 @@ export class Router {
partialState = {}; partialState = {};
let combined = {...currentState, ...partialState}; let combined = {...currentState, ...partialState};
// prevent: Uncaught TypeError: Expected "component" to match "[^\/#\?]+?", but got "" try {
if (combined.component === '') { return generateUrls(this.router)(this.routeName, combined);
combined.component = 'root'; } 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 = "") { dispatchLocationChanged(referrerUrl = "") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment