File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
3
import { Provider } from 'react-redux' ;
4
- import { BrowserRouter } from 'react-router-dom' ;
4
+ import { BrowserRouter as Router } from 'react-router-dom' ;
5
5
import store from './src/store' ;
6
6
import Layout from './src/Layout' ;
7
+ import ScrollToTop from './src/components/ScrollToTop' ;
7
8
8
9
const App = ( ) => (
9
10
< Provider store = { store } >
10
- < BrowserRouter >
11
- < Layout />
12
- </ BrowserRouter >
11
+ < Router >
12
+ < ScrollToTop >
13
+ < Layout />
14
+ </ ScrollToTop >
15
+ </ Router >
13
16
</ Provider >
14
17
) ;
15
18
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