|| pathName.startsWith("/user");
}
+ /**
+ * @property {string} pathname
+ * @property {string} search
+ * @property {function():void} update
+ * @type {Object}
+ */
+ const loadedPage = {
+ pathname: window.location.pathname,
+ search: window.location.search,
+ update() {
+ this.pathname = window.location.pathname;
+ this.search = window.location.search;
+ }
+ };
+
/**
* @param {URL} url
* @param {string} stateMode
}
(async function () {
- const prevUrl = new URL(window.location.href);
const newState = {"href": url.href, "hash": url.hash, "index": history.state.index + 1};
- if (stateMode === "pop" && history.state.hash === "") {
- window.scroll(0, history.state.scroll);
- return;
- } else if (stateMode !== "pop" && formData == null && url.pathname === prevUrl.pathname && url.search === prevUrl.search) {
- newState.href = "";
-
- if (stateMode === "push") {
- history.replaceState({...history.state, "scroll": window.scrollY}, "");
- history.pushState(newState, "", url);
- } else if (stateMode === "replace") {
- history.replaceState(newState, "", url);
- }
+ if (formData == null && url.pathname === loadedPage.pathname && url.search === loadedPage.search) {
+ if (stateMode === "pop") {
+ window.scroll(0, history.state.scroll);
+ } else {
+ newState.href = "";
- const scrollToElement = url.hash === "" ? null : document.querySelector(url.hash);
- if (scrollToElement != null) {
- scrollToElement.scrollIntoView(true);
+ if (stateMode === "push") {
+ history.replaceState({...history.state, "scroll": window.scrollY}, "");
+ history.pushState(newState, "", url);
+ } else if (stateMode === "replace") {
+ history.replaceState(newState, "", url);
+ }
+
+ const scrollToElement = url.hash === "" ? null : document.querySelector(url.hash);
+ if (scrollToElement != null) {
+ scrollToElement.scrollIntoView(true);
+ }
}
return;
replaceElement(document.body, htmlDocument.body);
onDomLoad(document.body);
+
+ loadedPage.update();
+
if (stateMode === "pop") {
window.scroll(0, history.state.scroll);
- } else if (url.hash !== '') {
+ } else if (url.hash !== "") {
const scrollToElement = document.querySelector(url.hash);
if (scrollToElement != null) {
scrollToElement.scrollIntoView(true);
return true;
}
- history.replaceState({"href": window.location.href, "hash": window.location.hash, "index": 0}, "");
+ history.replaceState({...(history.state ?? {"index": 0}), "href": window.location.href, "hash": window.location.hash}, "");
let isWindowScrollTicking = false;
window.addEventListener("scroll", () => {