From da475f6090d6331d5d6632d793fec499e5e31565 Mon Sep 17 00:00:00 2001 From: codebelt Date: Mon, 9 Oct 2017 19:31:17 -0500 Subject: [PATCH] Add react-router-redux history push example --- src/views/home/Home.jsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/views/home/Home.jsx b/src/views/home/Home.jsx index 627a555..cc630db 100644 --- a/src/views/home/Home.jsx +++ b/src/views/home/Home.jsx @@ -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'; @@ -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', @@ -42,10 +46,17 @@ class Home extends React.Component {

+ ); } + _onClickPushExample(event) { + event.preventDefault(); + + this.props.historyPush('/About'); + } + } export default connect(mapStateToProps, mapDispatchToProps)(Home);