christianalfoni / reactive-router

A reactive wrapper around Page JS
MIT License
46 stars 1 forks source link

Scroll to top of the page on route change #10

Open bobiblazeski opened 8 years ago

bobiblazeski commented 8 years ago

Is it possible to scroll automatically to top of the page on route change like https://github.com/rackt/react-router/blob/21f4f577774233e6ad3c78103fbdbad39ba69ff6/docs/api/components/Route.md#preservescrollposition

christianalfoni commented 8 years ago

Jup, just point to the container where you want to scroll to the top and set scrollTop = 0. You do this in the component where you need to scroll to the top and check if the url has changed. Like:

componentDidUpdate(prevProps) {
  if (prevProps.url !== this.props.url) {
    this.refs.mainContainer.scrollTop = 0;
  }
}