File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-undef */
2
+ import { Component } from 'react' ;
3
+ import { withRouter } from 'react-router-dom' ;
4
+
5
+ class ScrollToTop extends Component {
6
+ componentDidUpdate ( prevProps ) {
7
+ const { location } = this . props ;
8
+ if ( location . pathname !== prevProps . location . pathname ) {
9
+ window . scrollTo ( 0 , 0 ) ;
10
+ }
11
+ }
12
+
13
+ render ( ) {
14
+ const { children } = this . props ;
15
+ return children ;
16
+ }
17
+ }
18
+
19
+ export default withRouter ( ScrollToTop ) ;
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 { BrowserRouter } from 'react-router-dom' ;
4
+ import ScrollToTop from './components/tools/ScrollToTop' ;
4
5
5
6
import './index.css' ;
6
7
import App from './App' ;
@@ -9,7 +10,9 @@ import 'bootstrap/dist/css/bootstrap.min.css';
9
10
10
11
const app = (
11
12
< BrowserRouter >
12
- < App />
13
+ < ScrollToTop >
14
+ < App />
15
+ </ ScrollToTop >
13
16
</ BrowserRouter >
14
17
) ;
15
18
You can’t perform that action at this time.
0 commit comments