File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
22import ReactDOM from 'react-dom' ;
33import { Provider } from 'react-redux' ;
4- import { BrowserRouter } from 'react-router-dom' ;
4+ import { BrowserRouter as Router } from 'react-router-dom' ;
55import store from './src/store' ;
66import Layout from './src/Layout' ;
7+ import ScrollToTop from './src/components/ScrollToTop' ;
78
89const App = ( ) => (
910 < Provider store = { store } >
10- < BrowserRouter >
11- < Layout />
12- </ BrowserRouter >
11+ < Router >
12+ < ScrollToTop >
13+ < Layout />
14+ </ ScrollToTop >
15+ </ Router >
1316 </ Provider >
1417) ;
1518
Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+ import { withRouter } from 'react-router-dom' ;
4+
5+ class ScrollToTop extends Component {
6+ componentDidUpdate ( prevProps ) {
7+ if ( this . props . location . pathname !== prevProps . location . pathname ) {
8+ window . scrollTo ( 0 , 0 ) ;
9+ }
10+ }
11+
12+ render ( ) {
13+ return this . props . children ;
14+ }
15+ }
16+
17+ ScrollToTop . propTypes = {
18+ location : PropTypes . object . isRequired ,
19+ children : PropTypes . object . isRequired
20+ } ;
21+
22+ export default withRouter ( ScrollToTop ) ;
You can’t perform that action at this time.
0 commit comments