From f710430f53f7ae7d98bc99960eed6e8d7a7212a6 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 8 May 2021 21:15:20 +0200 Subject: [PATCH] Add defaultLocation --- www/res/js/locutus.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/www/res/js/locutus.js b/www/res/js/locutus.js index e347749..d7e0eac 100644 --- a/www/res/js/locutus.js +++ b/www/res/js/locutus.js @@ -1,6 +1,7 @@ "use strict"; let main, windows; +let defaultLocation = '/welcome'; function createWelcomeWindow() { let win = document.createElement("div"); @@ -32,7 +33,8 @@ function createLoginWindow() { function handleHash(hash) { if (hash[0] === '#') hash = hash.substr(1); - if (hash === '') hash = '/welcome'; + if (hash === '') hash = defaultLocation; + switch (hash) { case "/welcome": createWelcomeWindow(); break; case "/login": createLoginWindow(); break; @@ -41,13 +43,19 @@ function handleHash(hash) { hash = "/welcome"; break; } + let url = new URL(document.URL); url.hash = hash; location.href = url.toString(); } function handleUrl(url) { - handleHash(new URL(url).hash) + let hash = new URL(url).hash; + if (hash === '') { + history.replaceState(null, null, `#${defaultLocation}`); + } else { + handleHash(hash); + } } window.addEventListener("load", function () {