Skip to content

NPM Package to enable scroll to top on navigate for React Router DOM while maintaining scroll for previous pages on use of Back button.

License

Notifications You must be signed in to change notification settings

llleeeaaannn/scroll-to-top-react-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

About

NPM Package to enable scroll to top on navigate for React Router DOM while maintaining scroll for previous pages on use of Back button.

Topics

Resources

License

Stars

Watchers

Forks