diff --git a/src/App.tsx b/src/App.tsx index 8eafb448..cada3b21 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import Footer from "./components/Footer"; import ScrollProgressBar from "./components/ScrollProgressBar"; import { Toaster } from "react-hot-toast"; import Router from "./Routes/Router"; +import ScrollToTop from "./components/ScrollToTop"; const FULLSCREEN_ROUTES = ["/signup", "/login"]; @@ -13,6 +14,7 @@ function App() { return (
+ {!isFullscreen && } {!isFullscreen && } diff --git a/src/components/ScrollToTop.tsx b/src/components/ScrollToTop.tsx new file mode 100644 index 00000000..15f6d95b --- /dev/null +++ b/src/components/ScrollToTop.tsx @@ -0,0 +1,15 @@ +import {useEffect} from 'react'; +import {useLocation} from 'react-router-dom'; +/** + * Resets the window scroll position to the top + * whenever the route pathname changes. + */ +function ScrollToTop() { + const location = useLocation(); + useEffect(() => { + window.scrollTo(0, 0); + },[location.pathname]); + + return null; +} +export default ScrollToTop; \ No newline at end of file