JAckWang JAckWang - 3 months ago 61
React JSX Question

How to use react-router-redux routeActions?

I'm trying to modify the example code of react-router-redux.
https://github.com/rackt/react-router-redux/blob/master/examples/basic/components/Home.js

this is my Home.js

class Home extends Component {
onSubmit(props) {
this.props.routeActions.push('/foo');
}
}


I also have a mapDispatchToProps for it.

function mapDispatchToProps(dispatch){
return bindActionCreators({ routeActions },dispatch);
}


When i called onSubmit function, I got an error

Uncaught TypeError: this.props.routeActions.push is not a function


If i remove this.props in onSubmit, the key in the URL changed but its still on the same page.
From
localhost:8080/#/?_k=iwio19
to
localhost:8080/#/?_k=ldn1ew


Anyone know how to fix it?
Appreciate it.

Answer

I dont think routeActions are passed as props. What you want to do is this.

import { routeActions } from 'react-router-redux'

this.props.dispatch(routeActions.push('/foo));