Skip to content

Commit 3e45c44

Browse files
committed
update to react-hot-loader 3 beta7 - add ScrollToTop when navigation
1 parent b10a61f commit 3e45c44

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-immutable-webpack-ssr-starter",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "React + React-Router + Redux + ImmutableJS + Bootstrap with with Server side rendering, Hot Reload and redux-devtools STARTER",
55
"main": "src/index.js",
66
"engines": {
@@ -121,7 +121,7 @@
121121
"react": "^15.6.1",
122122
"react-bootstrap": "^0.31.0",
123123
"react-dom": "^15.6.1",
124-
"react-hot-loader": "^3.0.0-beta.6",
124+
"react-hot-loader": "3.0.0-beta-7",
125125
"react-modal": "^1.7.7",
126126
"react-motion": "^0.5.0",
127127
"react-notification": "^6.7.0",

src/app/Root.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import configureStore from './redux/store/configureStore';
1313
import { createBrowserHistory } from 'history';
1414
import { fromJS } from 'immutable';
1515
import App from './containers/app/App';
16+
import ScrollToTop from './components/scrollToTop/ScrollToTop';
1617

1718
const preloadedState = window.__PRELOADED_STATE__;
1819
delete window.__PRELOADED_STATE__;
@@ -35,7 +36,9 @@ class Root extends Component {
3536
<Provider store={store}>
3637
<div>
3738
<Router history={syncedHistory}>
38-
<App />
39+
<ScrollToTop>
40+
<App />
41+
</ScrollToTop>
3942
</Router>
4043
</div>
4144
</Provider>

src/app/components/scrollToTop/ScrollToTop.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import React, {
44
PureComponent
55
} from 'react';
66
import PropTypes from 'prop-types';
7+
import {
8+
withRouter
9+
} from 'react-router-dom';
710

811
class ScrollToTop extends PureComponent {
912
static propTypes = {
1013
children: PropTypes.node,
11-
location: PropTypes.string
14+
location: PropTypes.object
1215
};
1316

1417
componentDidUpdate(prevProps) {
15-
if (this.props.location !== prevProps.location) {
18+
const { location: nextLocation } = this.props;
19+
const { location: prevLocation } = prevProps;
20+
21+
if (nextLocation !== prevLocation) {
1622
window.scrollTo(0, 0);
1723
}
1824
}
@@ -27,4 +33,4 @@ class ScrollToTop extends PureComponent {
2733
}
2834
}
2935

30-
export default ScrollToTop;
36+
export default withRouter(ScrollToTop);

src/app/containers/app/App.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, {
44
PureComponent
55
} from 'react';
6+
import PropTypes from 'prop-types';
67
import {
78
NavigationBar,
89
BackToTop
@@ -13,12 +14,19 @@ import MainRoutes from '../../routes/MainRoutes';
1314
import { withRouter } from 'react-router';
1415

1516
class App extends PureComponent {
17+
static propTypes = {
18+
// react-router 4:
19+
location: PropTypes.object,
20+
match: PropTypes.object
21+
};
22+
1623
state = {
1724
navModel : fromJS(navigationModel)
1825
};
1926

2027
render() {
2128
const { navModel } = this.state;
29+
const { match: { url } } = this.props;
2230

2331
return (
2432
<div id="appContainer">

src/app/views/about/About.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import React, {
44
PureComponent
55
} from 'react';
66
import PropTypes from 'prop-types';
7+
import {
8+
Jumbotron
9+
} from '../../components';
710
import AnimatedView from '../../containers/animatedView/AnimatedView';
11+
import { Link } from 'react-router-dom';
812

913
class About extends PureComponent {
10-
static propTypes= {
14+
static propTypes = {
1115
currentView: PropTypes.string.isRequired,
1216
enterAbout: PropTypes.func.isRequired,
1317
leaveAbout: PropTypes.func.isRequired
@@ -26,9 +30,20 @@ class About extends PureComponent {
2630
render() {
2731
return(
2832
<AnimatedView>
29-
<h1>
30-
About
31-
</h1>
33+
<Jumbotron>
34+
<h1>
35+
About
36+
</h1>
37+
<p>
38+
<Link
39+
className="btn btn-success btn-lg"
40+
to={'/'}>
41+
<i className="fa fa-info" />
42+
&nbsp;
43+
go to home
44+
</Link>
45+
</p>
46+
</Jumbotron>
3247
</AnimatedView>
3348
);
3449
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5631,7 +5631,7 @@ react-dom@^15.6.1:
56315631
object-assign "^4.1.0"
56325632
prop-types "^15.5.10"
56335633

5634-
react-hot-loader@^3.0.0-beta.6:
5634+
react-hot-loader@3.0.0-beta-7:
56355635
version "3.0.0-beta.7"
56365636
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-3.0.0-beta.7.tgz#d5847b8165d731c4d5b30d86d5d4716227a0fa83"
56375637
dependencies:

0 commit comments

Comments
 (0)