Skip to content

Commit 7ade001

Browse files
committed
fix: handle hash navigation to prevent duplicate callbacks
1 parent 84ba468 commit 7ade001

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

docs/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ If you have a link to the homepage in the sidebar and want it to be shown as act
917917

918918
For more details, see [#1131](https://github.com/docsifyjs/docsify/issues/1131).
919919

920-
## themeColor ⚠️
920+
## themeColor ⚠️ :id=themecolor
921921

922922
!> Deprecated as of v5. Use the `--theme-color` [theme property](themes#theme-properties) to [customize](themes#customization) your theme color.
923923

@@ -931,7 +931,7 @@ window.$docsify = {
931931
};
932932
```
933933

934-
## topMargin ⚠️
934+
## topMargin ⚠️ :id=topmargin
935935

936936
!> Deprecated as of v5. Use the `--scroll-padding-top` [theme property](themes#theme-properties) to specify a scroll margin when using a sticky navbar.
937937

src/core/router/history/hash.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ export class HashHistory extends History {
4646
const el = e.target.tagName === 'A' ? e.target : e.target.parentNode;
4747

4848
if (el && el.tagName === 'A' && !isExternal(el.href)) {
49+
const hrefHash = new URL(el.href).hash;
50+
const currentHash = location.hash;
51+
4952
navigating = true;
53+
54+
if (hrefHash && hrefHash === currentHash) {
55+
cb({ event: e, source: 'navigate' });
56+
}
5057
}
5158
});
5259

0 commit comments

Comments
 (0)