fix: nav event with spa off, anchor nav refresh page

This commit is contained in:
Jacky Zhao 2023-08-20 18:08:44 -07:00
parent 173ec240d2
commit 952d6cb3dd
2 changed files with 1 additions and 5 deletions

View file

@ -12,9 +12,6 @@ const isLocalUrl = (href: string) => {
try { try {
const url = new URL(href) const url = new URL(href)
if (window.location.origin === url.origin) { if (window.location.origin === url.origin) {
if (url.pathname === window.location.pathname) {
return !url.hash
}
return true return true
} }
} catch (e) {} } catch (e) {}
@ -94,7 +91,6 @@ function createRouter() {
window.addEventListener("click", async (event) => { window.addEventListener("click", async (event) => {
const { url } = getOpts(event) ?? {} const { url } = getOpts(event) ?? {}
if (!url) return if (!url) return
if (url.pathname === window.location.pathname) return
event.preventDefault() event.preventDefault()
try { try {
navigate(url, false) navigate(url, false)

View file

@ -103,7 +103,7 @@ function addGlobalPageResources(
} else { } else {
componentResources.afterDOMLoaded.push(` componentResources.afterDOMLoaded.push(`
window.spaNavigate = (url, _) => window.location.assign(url) window.spaNavigate = (url, _) => window.location.assign(url)
const event = new CustomEvent("nav", { detail: { slug: document.body.dataset.slug } }) const event = new CustomEvent("nav", { detail: { url: document.body.dataset.slug } })
document.dispatchEvent(event)`) document.dispatchEvent(event)`)
} }