ScrollToTop is a React component that scrolls to the top of a page when the current location gets changed. Since React Router doesn't provide out-of-the-box support for scroll restoration due to browsers having started handling it on their own, this package implements a component for scrolling to the top manually as it is given in React Router docs.
npm install react-router-scroll-to-top
import { ScrollToTop } from 'react-router-scroll-to-top';
const App = () => (
<BrowserRouter>
<ScrollToTop />
<Routes>{/* routes */}</Routes>
</BrowserRouter>
);
Read the documentation for more details. You can also play with a demo.
If you like this package and want to support it, you can do it on Patreon