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) {
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 () {