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
npm install scroll-to-top-react-router
import ScrollToTop from 'scroll-to-top-react-router'
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>