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) {
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);
......
......@@ -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 = "") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment