(async function () {
const prevUrl = new URL(window.location.href);
- const newState = {"href": url.href, "index": history.state.index + 1};
+ const newState = {"href": url.href, "hash": url.hash, "index": history.state.index + 1};
- if (stateMode === "pop" && history.state.href === "") {
+ if (stateMode === "pop" && history.state.hash === "") {
window.scroll(0, history.state.scroll);
return;
} else if (stateMode !== "pop" && url.pathname === prevUrl.pathname && url.search === prevUrl.search) {
history.replaceState(newState, "", url);
}
- const scrollToElement = document.querySelector(url.hash);
+ const scrollToElement = url.hash === "" ? null : document.querySelector(url.hash);
if (scrollToElement != null) {
scrollToElement.scrollIntoView(true);
}
return;
}
- const redirectUrl = new URL(redirectJsonBody.target, window.location.origin)
+ const redirectUrl = new URL(redirectJsonBody.target, window.location.origin);
if (!goToPage(redirectUrl, "push")) {
window.location.href = redirectUrl.href;
}
return true;
}
- history.replaceState({"href": window.location.href, "index": 0}, "");
+ history.replaceState({"href": window.location.href, "hash": window.location.hash, "index": 0}, "");
let isWindowScrollTicking = false;
window.addEventListener("scroll", () => {