react-scroll-on-navigate
v0.1.3
Published
Scroll to top automatically on navigate.
Downloads
10
Maintainers
Readme
React Scroll on Navigate
Scroll to top automatically when the route changes. Works well with React Router and other similar tools.
See the React Router guide for more details.
Usage
Manually, passing in your router's location
prop:
import { ScrollToTopOnNavigate } from 'react-scroll-on-navigate';
<div className="MyApp">
<ScrollToTopOnNavigate location={location} />
...
</div>
Or, using a decorator if you prefer:
import { ScrollToTopOnNavigate as ScrollToTopWithoutRouter } from 'lsr-lib';
import { withRouter } from 'react-router';
const ScrollToTopOnNavigate = withRouter(ScrollToTopWithoutRouter);
<div className="MyApp">
<ScrollToTopOnNavigate />
...
</div>