Обнуление скролла при переходе между страницами

This commit is contained in:
ifraimka1 committed 2025-03-24 19:01:41 +03:00
1 parent 5d1c74b212
commit 3a1cac0dfe
2 files changed
+16

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
const ScrollToTop = () => {
const { pathname } = useLocation();
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
return null;
};
export default ScrollToTop;
+2
View File
@@ -2,6 +2,7 @@ import { Outlet } from "react-router-dom";
import { createContext, useEffect, useState } from 'react';
import useElementOnScreen from '../../lib/useElementOnScreen';
import ScrollToTop from "../../lib/scrollToTop";
import Navbar from '../../components/Navbar';
import Footer from '../../components/Footer';
import './Root.styles.scss';
@@ -63,6 +64,7 @@ function Root() {
return (
<RootContext.Provider value={{ setRef }}>
<ScrollToTop />
<Navbar />
<div id="react-page">
<Outlet />