Skip to content

Commit

Permalink
fix(router): scroll back to the hash anchor even if it is already sel…
Browse files Browse the repository at this point in the history
…ected (#2265)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
lchzh3473 and brc-dd committed Apr 21, 2023
1 parent 6421eda commit f3d3332
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}
Expand Down

0 comments on commit f3d3332

Please sign in to comment.