diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index e04a133..2dede35 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -64,9 +64,8 @@ export function Footer() { return ( <> - + { + useLayoutEffect(() => { function handleScroll() { - sessionStorage.setItem(location.key, JSON.stringify(window.scrollY)); + sessionStorage.setItem(location.pathname, JSON.stringify(window.scrollY)); } window.addEventListener('scroll', handleScroll); - const scrollPosition = sessionStorage.getItem(location.key); + const scrollPosition = sessionStorage.getItem(location.pathname); + if (scrollPosition && !loading) { window.scrollTo(0, JSON.parse(scrollPosition)); } @@ -19,5 +20,5 @@ export function useScrollRestoration(loading) { return () => { window.removeEventListener('scroll', handleScroll); }; - }, [location.key, loading]); + }, [location.pathname, loading]); } diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 9fd4d0f..1a24e13 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -48,6 +48,7 @@ export function Home() { urlImage='https://xbu.netlify.app/ogImage.png' /> { let isMounted = true; diff --git a/src/pages/profile/Profile.tsx b/src/pages/profile/Profile.tsx index 95af195..86083b9 100644 --- a/src/pages/profile/Profile.tsx +++ b/src/pages/profile/Profile.tsx @@ -195,6 +195,7 @@ export function Profile() { urlImage={data?.pages[0].user.picture} />