Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: scroll to ref doc section when going back/forward

Greg Richardson8e19b5fdf526
diff --git a/apps/docs/components/reference/RefSectionHandler.tsx b/apps/docs/components/reference/RefSectionHandler.tsx
index eb0dbdc7455..107a2c788a3 100644
--- a/apps/docs/components/reference/RefSectionHandler.tsx
+++ b/apps/docs/components/reference/RefSectionHandler.tsx
@@ -26,10 +26,21 @@ const RefSectionHandler = (props: RefSectionHandlerProps) => {
// When user lands on a url like http://supabase.com/docs/reference/javascript/sign-up
// find the #sign-up element and scroll to that
useEffect(() => {
- if (document && slug !== 'start') {
- document.querySelector(`#${slug}`) && document.querySelector(`#${slug}`).scrollIntoView()
+ document.getElementById(slug)?.scrollIntoView()
+ }, [slug])
+
+ useEffect(() => {
+ function handler(e: PopStateEvent) {
+ const [slug] = window.location.pathname.split('/').slice(-1)
+ document.getElementById(slug)?.scrollIntoView()
+ }
+
+ window.addEventListener('popstate', handler)
+
+ return () => {
+ window.removeEventListener('popstate', handler)
}
- })
+ }, [])
function getPageTitle() {
switch (props.type) {