Skip to content

chore(docs): fix TOC navigation anchor links (fixes #7250) #7251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const offsetTop = $el =>

// Scroll an in-page link target into view
export const scrollTargetIntoView = (event, href) => {
event.preventDefault()
event.stopPropagation()
// We use an attribute `querySelector()` rather than `getElementByID()`,
// as some auto-generated ID's are invalid or not unique
Expand All @@ -223,6 +224,14 @@ export const scrollTargetIntoView = (event, href) => {
$el.tabIndex = -1
// Focus the heading
$el.focus()
// Update the URL to show the hash without changing the current path
const currentPath = window.location.pathname + window.location.search
if (history.pushState) {
history.pushState(null, null, currentPath + '#' + id)
} else {
// Fallback for older browsers
window.location.hash = id
}
})
}
}
Loading