Skip to content

Commit

Permalink
feat(website): restore scrol position when pathname changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed May 19, 2018
1 parent a360e44 commit 49b7ffc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions website/src/components/ScrollToTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { withRouter } from 'react-router-dom'

class ScrollToTop extends Component {
componentDidUpdate(prevProps) {
console.log(this.props.location !== prevProps.location)
if (this.props.location !== prevProps.location) {
if (this.props.location.pathname !== prevProps.location.pathname) {
window.scrollTo(0, 0)
}
}
Expand Down
6 changes: 3 additions & 3 deletions website/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Nav from './components/nav/Nav'
import MiniNav from './components/nav/MiniNav'
import Home from './components/pages/Home'
import Header from './components/Header'
//import ScrollToTop from './components/ScrollToTop'
import ScrollToTop from './components/ScrollToTop'
//import MobileNav from './components/nav/mobile/MobileNav'
import { getRoutes } from './SiteMap'
import registerServiceWorker from './registerServiceWorker'
Expand Down Expand Up @@ -60,12 +60,12 @@ class App extends Component {

render(
<Router>
<div>
<ScrollToTop>
<Switch>
<Route exact path="/" component={Home} />
<Route path="*" component={App} />
</Switch>
</div>
</ScrollToTop>
</Router>,
document.getElementById('root')
)
Expand Down

0 comments on commit 49b7ffc

Please sign in to comment.