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

Add react-router-redux history push example #30

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/views/home/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import {connect} from 'react-redux';
import {push} from 'react-router-redux';
import UserAction from '../../stores/user/UserAction';
import MetaAction from '../../stores/meta/MetaAction';

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

const mapDispatchToProps = (dispatch) => ({
historyPush: (route) => dispatch(push(route)),
loadUser: () => dispatch(UserAction.loadUser()),
setMeta: (meta) => dispatch(MetaAction.setMeta(meta)),
});

class Home extends React.Component {

_onClickPushExampleHandler = this._onClickPushExample.bind(this);

componentWillMount() {
this.props.setMeta({
title: 'Home Page',
Expand Down Expand Up @@ -42,10 +46,17 @@ class Home extends React.Component {
</button>
</p>
</div>
<button onClick={this._onClickPushExampleHandler}>{'Go to About'}</button>
</div>
);
}

_onClickPushExample(event) {
event.preventDefault();

this.props.historyPush('/About');
}

}

export default connect(mapStateToProps, mapDispatchToProps)(Home);
Expand Down