fix(router): hashchange not emitted in certain cases (#3637)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/3638/head
烽宁 9 months ago committed by GitHub
parent f6bd99eb13
commit 6b971a08f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -180,7 +180,7 @@ export function createRouter(
: link.href,
link.baseURI
)
const currentUrl = window.location
const currentUrl = new URL(window.location.href) // copy to keep old data
// only intercept inbound html links
if (
!e.ctrlKey &&
@ -211,7 +211,12 @@ export function createRouter(
window.scrollTo(0, 0)
}
} else {
go(href)
go(href).then(() => {
// do after the route is changed so location.hash in theme code is the new hash
if (hash !== currentUrl.hash) {
window.dispatchEvent(new Event('hashchange'))
}
})
}
}
}

Loading…
Cancel
Save