React-router: Scroll to top when clicking links (restore #121 for react-router 2)

Created on 6 Feb 2016  路  2Comments  路  Source: ReactTraining/react-router

Seems like the same issue as #121 exists again with v2. Is there a good reason it was dropped? Is it intentional for us to have to add

componentDidUpdate() {
  this.getDOMNode().scrollTop = 0 ;
},

to every component?

Most helpful comment

Adding the onUpdate to your router stops you from having to add the event to each component

<Router onUpdate={() => window.scrollTo(0, 0)} history={history}>
        {routes}
</Router>

All 2 comments

Dupe of a ton of other issues, search around.

Adding the onUpdate to your router stops you from having to add the event to each component

<Router onUpdate={() => window.scrollTo(0, 0)} history={history}>
        {routes}
</Router>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzimmek picture jzimmek  路  3Comments

stnwk picture stnwk  路  3Comments

davetgreen picture davetgreen  路  3Comments

imWildCat picture imWildCat  路  3Comments

hgezim picture hgezim  路  3Comments