fix(router): scroll back to the hash anchor even if it is already selected (#2265)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/2274/head
lchzh3473 1 year ago committed by GitHub
parent 6421eda558
commit f3d3332fff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -187,10 +187,13 @@ export function createRouter(
search === currentUrl.search
) {
// scroll between hash anchors in the same page
if (hash && hash !== currentUrl.hash) {
history.pushState(null, '', hash)
// still emit the event so we can listen to it in themes
window.dispatchEvent(new Event('hashchange'))
if (hash) {
// avoid duplicate history entries when the hash is same
if (hash !== currentUrl.hash) {
history.pushState(null, '', hash)
// still emit the event so we can listen to it in themes
window.dispatchEvent(new Event('hashchange'))
}
// use smooth scroll when clicking on header anchor links
scrollTo(link, hash, link.classList.contains('header-anchor'))
}

Loading…
Cancel
Save