Skip to content

Commit f3d3332

Browse files
lchzh3473brc-dd
andauthored
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>
1 parent 6421eda commit f3d3332

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/client/app/router.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ export function createRouter(
187187
search === currentUrl.search
188188
) {
189189
// scroll between hash anchors in the same page
190-
if (hash && hash !== currentUrl.hash) {
191-
history.pushState(null, '', hash)
192-
// still emit the event so we can listen to it in themes
193-
window.dispatchEvent(new Event('hashchange'))
190+
if (hash) {
191+
// avoid duplicate history entries when the hash is same
192+
if (hash !== currentUrl.hash) {
193+
history.pushState(null, '', hash)
194+
// still emit the event so we can listen to it in themes
195+
window.dispatchEvent(new Event('hashchange'))
196+
}
194197
// use smooth scroll when clicking on header anchor links
195198
scrollTo(link, hash, link.classList.contains('header-anchor'))
196199
}

0 commit comments

Comments
 (0)