react-router-scroll-to-top

React component that scrolls to the top of a page when the current location gets changed

Usage no npm install needed!

<script type="module">
  import reactRouterScrollToTop from 'https://cdn.skypack.dev/react-router-scroll-to-top';
</script>

README

react-router-scroll-to-top

npm Version npm downloads per week Minified size Open issues Open pull requests GitHub Stars CircleCI status Code scanning Storybook

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.

Usage

npm install react-router-scroll-to-top
import { ScrollToTop } from 'react-router-scroll-to-top';

const App = () => (
  <BrowserRouter>
    <ScrollToTop />
    <Switch>{/* routes */}</Switch>
  </BrowserRouter>
);

Read the documentation for more details. You can also play with a demo.

Support

If you like this package and want to support it, you can fund us on Patreon