Add defaultLocation
This commit is contained in:
@ -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 () {
|
||||
|
Reference in New Issue
Block a user