Skip to content

Commit a12b3d6

Browse files
committed
feat: 一点小东西
1 parent 8fde7cd commit a12b3d6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/components/modules/toc/TocTree.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ function useActiveId($headings: HTMLHeadingElement[]) {
3131
entries.forEach((entry) => {
3232
if (entry.isIntersecting) {
3333
startTransition(() => {
34-
if (activeId != entry.target.id) setActiveId(entry.target.id);
34+
if (activeId != entry.target.id) {
35+
setActiveId(entry.target.id);
36+
37+
const { state } = history;
38+
history.replaceState(state, '', `#${entry.target.id}`);
39+
}
3540
});
3641
}
3742
});
@@ -106,6 +111,9 @@ export const TocTree = ({
106111
const handle = () => {
107112
springScrollToElement($el, -100).then(() => {
108113
setActiveId?.(anchorId);
114+
115+
const { state } = history;
116+
history.replaceState(state, '', `#${anchorId}`);
109117
});
110118
};
111119

0 commit comments

Comments
 (0)