npm.io
2.0.0 • Published 19h ago

react-router-scroll-to-top

Licence
MIT
Version
2.0.0
Deps
0
Size
9 kB
Vulns
0
Weekly
0

react-router-scroll-to-top

npm Version npm downloads per week Unpacked size Open issues Open pull requests GitHub Stars CI status Code scanning

ScrollToTop is a React component that scrolls to the top of the page when the location changes. It's for apps that use React Router 7 or 8 in declarative mode, with <BrowserRouter>, where React Router has no built-in scroll handling. For React Router 5.1 or 6, use version 1 of this package.

If your app uses a data router (createBrowserRouter with <RouterProvider>) or framework mode, use React Router's <ScrollRestoration> instead. It also restores the scroll position when users go back or forward.

Usage

npm install react-router-scroll-to-top
import { BrowserRouter, Routes } from 'react-router';
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.

Keywords