scroll-to-top-react-router
v1.7.3
Published
Scroll to top on navigate for React Router DOM while maintaining scroll for previous pages on use of Back button
Downloads
9
Maintainers
Readme
Scroll to Top on Navigate for React Router
Creates automatic scroll-to-top behaviour when the route changes. The package also preserves previous pages' scroll position upon navigating back with the Back button.
Works with the latest version of React Router
Install
npm install scroll-to-top-react-router
Import
import ScrollToTop from 'scroll-to-top-react-router'
Usage
Use inside the Router component, for example as below in App.js:
<Router>
<ScrollToTop />
<Routes>
<Route path="/" exact component={Home} />
<Route path="/about" exact component={About} />
</Routes>
</Router>