Fix history.replaceState

This commit is contained in:
2021-05-09 10:56:29 +02:00
parent 68518d28e7
commit f77882baf7

View File

@ -33,15 +33,15 @@ function createLoginWindow() {
function handleHash(hash) { function handleHash(hash) {
if (hash[0] === '#') hash = hash.substr(1); if (hash[0] === '#') hash = hash.substr(1);
if (hash === '') hash = defaultLocation;
switch (hash) { switch (hash) {
case "/welcome": createWelcomeWindow(); break; case "/welcome": createWelcomeWindow(); break;
case "/login": createLoginWindow(); break; case "/login": createLoginWindow(); break;
default: default:
console.error(`Invalid url hash "${hash}"`); console.warn(`Invalid url hash #${hash}`);
hash = defaultLocation; history.replaceState(null, null, `#${defaultLocation}`);
break; handleHash(defaultLocation)
return;
} }
let url = new URL(document.URL); let url = new URL(document.URL);
@ -50,12 +50,7 @@ function handleHash(hash) {
} }
function handleUrl(url) { function handleUrl(url) {
let hash = new URL(url).hash; handleHash(new URL(url).hash);
if (hash === '') {
history.replaceState(null, null, `#${defaultLocation}`);
hash = defaultLocation;
}
handleHash(hash);
} }
window.addEventListener("load", function () { window.addEventListener("load", function () {