From f77882baf7e8d9afa6a2ea69435ddbbc51996daf Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sun, 9 May 2021 10:56:29 +0200 Subject: [PATCH] Fix history.replaceState --- www/res/js/locutus.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/www/res/js/locutus.js b/www/res/js/locutus.js index dc18112..b10a7f5 100644 --- a/www/res/js/locutus.js +++ b/www/res/js/locutus.js @@ -33,15 +33,15 @@ function createLoginWindow() { function handleHash(hash) { if (hash[0] === '#') hash = hash.substr(1); - if (hash === '') hash = defaultLocation; switch (hash) { case "/welcome": createWelcomeWindow(); break; case "/login": createLoginWindow(); break; default: - console.error(`Invalid url hash "${hash}"`); - hash = defaultLocation; - break; + console.warn(`Invalid url hash #${hash}`); + history.replaceState(null, null, `#${defaultLocation}`); + handleHash(defaultLocation) + return; } let url = new URL(document.URL); @@ -50,12 +50,7 @@ function handleHash(hash) { } function handleUrl(url) { - let hash = new URL(url).hash; - if (hash === '') { - history.replaceState(null, null, `#${defaultLocation}`); - hash = defaultLocation; - } - handleHash(hash); + handleHash(new URL(url).hash); } window.addEventListener("load", function () {