Skip to content
This repository was archived by the owner on Nov 16, 2018. It is now read-only.

Commit cc20f2c

Browse files
authored
Add react-router-redux history push example (#30)
1 parent 61a67ca commit cc20f2c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/views/home/Home.jsx

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import {connect} from 'react-redux';
3+
import {push} from 'react-router-redux';
34
import UserAction from '../../stores/user/UserAction';
45
import MetaAction from '../../stores/meta/MetaAction';
56

@@ -8,12 +9,15 @@ const mapStateToProps = (state) => ({
89
});
910

1011
const mapDispatchToProps = (dispatch) => ({
12+
historyPush: (route) => dispatch(push(route)),
1113
loadUser: () => dispatch(UserAction.loadUser()),
1214
setMeta: (meta) => dispatch(MetaAction.setMeta(meta)),
1315
});
1416

1517
class Home extends React.Component {
1618

19+
_onClickPushExampleHandler = this._onClickPushExample.bind(this);
20+
1721
componentWillMount() {
1822
this.props.setMeta({
1923
title: 'Home Page',
@@ -42,10 +46,17 @@ class Home extends React.Component {
4246
</button>
4347
</p>
4448
</div>
49+
<button onClick={this._onClickPushExampleHandler}>{'Go to About'}</button>
4550
</div>
4651
);
4752
}
4853

54+
_onClickPushExample(event) {
55+
event.preventDefault();
56+
57+
this.props.historyPush('/About');
58+
}
59+
4960
}
5061

5162
export default connect(mapStateToProps, mapDispatchToProps)(Home);

0 commit comments

Comments
 (0)