Skip to content

Commit

Permalink
Merge pull request #871 from vtexdocs/fix/hash-links-in-api-references
Browse files Browse the repository at this point in the history
chore(api-reference): update the position in the sidebar when an api-…
  • Loading branch information
carolinamenezes authored Jan 29, 2025
2 parents 8bb7f80 + 40f56d3 commit 4ddd6c5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/pages/docs/api-reference/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ const APIPage: NextPage<Props> = ({
}
}, [])

useEffect(() => {
const handleHashChange = () => {
const newHash = window.location.hash.substring(1)
router.push(`${window.location.pathname}?endpoint=${newHash}`)
}

window.addEventListener('hashchange', handleHashChange)

return () => {
window.removeEventListener('hashchange', handleHashChange)
}
}, [router])

useEffect(() => {
setEndpointPagination(
pagination[endpointPath] ? pagination[endpointPath] : pag
Expand Down

0 comments on commit 4ddd6c5

Please sign in to comment.