Add defaultLocation

This commit is contained in:
2021-05-08 21:15:20 +02:00
parent fedd45b83c
commit f710430f53

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
let main, windows; let main, windows;
let defaultLocation = '/welcome';
function createWelcomeWindow() { function createWelcomeWindow() {
let win = document.createElement("div"); let win = document.createElement("div");
@ -32,7 +33,8 @@ 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 = '/welcome'; if (hash === '') hash = defaultLocation;
switch (hash) { switch (hash) {
case "/welcome": createWelcomeWindow(); break; case "/welcome": createWelcomeWindow(); break;
case "/login": createLoginWindow(); break; case "/login": createLoginWindow(); break;
@ -41,13 +43,19 @@ function handleHash(hash) {
hash = "/welcome"; hash = "/welcome";
break; break;
} }
let url = new URL(document.URL); let url = new URL(document.URL);
url.hash = hash; url.hash = hash;
location.href = url.toString(); location.href = url.toString();
} }
function handleUrl(url) { 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 () { window.addEventListener("load", function () {