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 2 years 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 search === currentUrl.search
) { ) {
// scroll between hash anchors in the same page // scroll between hash anchors in the same page
if (hash && hash !== currentUrl.hash) { if (hash) {
// avoid duplicate history entries when the hash is same
if (hash !== currentUrl.hash) {
history.pushState(null, '', hash) history.pushState(null, '', hash)
// still emit the event so we can listen to it in themes // still emit the event so we can listen to it in themes
window.dispatchEvent(new Event('hashchange')) window.dispatchEvent(new Event('hashchange'))
}
// use smooth scroll when clicking on header anchor links // use smooth scroll when clicking on header anchor links
scrollTo(link, hash, link.classList.contains('header-anchor')) scrollTo(link, hash, link.classList.contains('header-anchor'))
} }

Loading…
Cancel
Save