diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.js | 5 | ||||
| -rw-r--r-- | src/pages.js | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/index.js b/src/index.js index e6a4dc3..cac7bf4 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ const albums = new Page(document.querySelector("#albums"), "/albums") const settings = new Page(document.querySelector("#settings"), "/settings") window.addEventListener("popstate", Page.pathnameCallback) -Page.pathnameCallback() +Page.pathnameCallback() /* run after all pages are registered */ /* add event listeners for anchor elements in footer */ function softRedirect(e) { @@ -22,8 +22,7 @@ function softRedirect(e) { while (a.tagName !== "A" && a !== null) a = a.parentElement if (a === null) return - window.history.pushState({}, "", a.href); - Page.pathnameCallback() + Page.softRedirect(a.href) } document.querySelector("#menu").addEventListener("click", softRedirect) diff --git a/src/pages.js b/src/pages.js index 7e0bdbc..3a02454 100644 --- a/src/pages.js +++ b/src/pages.js @@ -16,6 +16,11 @@ export default class Page { Page.currentPage = page } + static softRedirect(path) { + window.history.pushState({}, "", path) + Page.pathnameCallback() + } + constructor(pageContainer, endpoint, f_initialize) { Page.pages[endpoint] = this |
