🌐 AI搜索 & 代理 主页
Skip to content

Commit 31106fc

Browse files
committed
chore(docs): fix TOC navigation anchor links
1 parent 46360a7 commit 31106fc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/utils/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export const offsetTop = $el =>
209209

210210
// Scroll an in-page link target into view
211211
export const scrollTargetIntoView = (event, href) => {
212+
event.preventDefault()
212213
event.stopPropagation()
213214
// We use an attribute `querySelector()` rather than `getElementByID()`,
214215
// as some auto-generated ID's are invalid or not unique
@@ -223,6 +224,14 @@ export const scrollTargetIntoView = (event, href) => {
223224
$el.tabIndex = -1
224225
// Focus the heading
225226
$el.focus()
227+
// Update the URL to show the hash without changing the current path
228+
const currentPath = window.location.pathname + window.location.search
229+
if (history.pushState) {
230+
history.pushState(null, null, currentPath + '#' + id)
231+
} else {
232+
// Fallback for older browsers
233+
window.location.hash = id
234+
}
226235
})
227236
}
228237
}

0 commit comments

Comments
 (0)