Router: scroll to top on route change

This commit is contained in:
He4eT 2023-05-24 03:17:07 +03:00 committed by Alexey
commit 9de3d951e5

View file

@ -9,10 +9,13 @@ export const useHashLocation = () => {
const [loc, setLoc] = useState(currentLoc()) const [loc, setLoc] = useState(currentLoc())
useEffect(() => { useEffect(() => {
const handler = () => setLoc(currentLoc()) const handler = () => {
setLoc(currentLoc())
window.scrollTo(0, 0)
}
window.addEventListener('hashchange', handler)
handler() handler()
window.addEventListener('hashchange', handler)
return () => window.removeEventListener('hashchange', handler) return () => window.removeEventListener('hashchange', handler)
}, []) }, [])