fix anchor navigation (#87)

Co-authored-by: rafapaezbas <rafa@holepunch.com>
This commit is contained in:
rafapaezbas
2024-03-08 14:49:24 +01:00
committed by GitHub
parent 0bb3fc9232
commit 540765a780
2 changed files with 4 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
super()
this.routes = {}
this.page = null
this.anchor = null
}
unload () {
@@ -11,8 +12,9 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
}
async load (pathname = '/', opts = {}) {
if (this.page === pathname) return
if (this.page === pathname && this.anchor === opts.anchor) return
this.page = pathname
this.anchor = opts.anchor
for (const [route, element] of Object.entries(this.routes)) {
if (pathname.startsWith(route)) {
const page = pathname.slice(route.length) || '/'