From e6096cc2e343febbdce43bf3a0a4f25881e30f75 Mon Sep 17 00:00:00 2001 From: Carolina Menezes Date: Wed, 29 Jan 2025 16:33:48 -0300 Subject: [PATCH] chore(api-reference): update the position in the sidebar when an api-reference hash link is clicked fix issues with hash links in api references --- src/pages/docs/api-reference/[slug].tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pages/docs/api-reference/[slug].tsx b/src/pages/docs/api-reference/[slug].tsx index 8f49ba6d2..671652b85 100644 --- a/src/pages/docs/api-reference/[slug].tsx +++ b/src/pages/docs/api-reference/[slug].tsx @@ -121,6 +121,19 @@ const APIPage: NextPage = ({ } }, []) + 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