17 lines
429 B
TypeScript
17 lines
429 B
TypeScript
import { useEffect } from "react";
|
|
import { useLocation, useNavigationType } from "react-router-dom";
|
|
|
|
export default function ScrollToTop() {
|
|
const { pathname } = useLocation();
|
|
const navigationType = useNavigationType();
|
|
|
|
useEffect(() => {
|
|
if (navigationType !== "POP") {
|
|
window.scrollTo(0, 0);
|
|
}
|
|
// Only scrolls to top on PUSH or REPLACE, not on POP
|
|
}, [pathname, navigationType]);
|
|
|
|
return null;
|
|
}
|