Queue-North-Website/src/components/ScrollToTop.jsx

18 lines
407 B
React
Raw Normal View History

import { useEffect } from 'react'
import { useLocation } from 'react-router-dom'
export default function ScrollToTop() {
2026-05-27 22:33:54 -05:00
const { pathname, hash } = useLocation()
useEffect(() => {
2026-05-27 22:33:54 -05:00
if (hash) {
const el = document.querySelector(hash)
if (el) {
el.scrollIntoView({ behavior: 'smooth' })
return
}
}
window.scrollTo(0, 0)
2026-05-27 22:33:54 -05:00
}, [pathname, hash])
return null
}