From 9de3d951e5f2ec21d6b9c16765a854a2fb4aebc1 Mon Sep 17 00:00:00 2001 From: He4eT Date: Wed, 24 May 2023 03:17:07 +0300 Subject: [PATCH] Router: scroll to top on route change --- src/utils/utils.routing.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/utils.routing.js b/src/utils/utils.routing.js index 4a91bbf..25a3084 100644 --- a/src/utils/utils.routing.js +++ b/src/utils/utils.routing.js @@ -9,10 +9,13 @@ export const useHashLocation = () => { const [loc, setLoc] = useState(currentLoc()) useEffect(() => { - const handler = () => setLoc(currentLoc()) + const handler = () => { + setLoc(currentLoc()) + window.scrollTo(0, 0) + } - window.addEventListener('hashchange', handler) handler() + window.addEventListener('hashchange', handler) return () => window.removeEventListener('hashchange', handler) }, [])