mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-04 17:07:22 +00:00
Router: scroll to top on route change
This commit is contained in:
parent
e1267730bb
commit
9de3d951e5
1 changed files with 5 additions and 2 deletions
|
|
@ -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)
|
||||
}, [])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue