如何使用 react-router-redux routeActions? [英] How to use react-router-redux routeActions?
问题描述
我正在尝试修改 react-router-redux 的示例代码.https://github.com/rackt/react-router-redux/blob/master/examples/basic/components/Home.js
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
这是我的 Home.js
this is my Home.js
class Home extends Component {
onSubmit(props) {
this.props.routeActions.push('/foo');
}
}
我也有一个 mapDispatchToProps.
I also have a mapDispatchToProps for it.
function mapDispatchToProps(dispatch){
return bindActionCreators({ routeActions },dispatch);
}
当我调用 onSubmit 函数时,出现错误
When i called onSubmit function, I got an error
Uncaught TypeError: this.props.routeActions.push is not a function
如果我在 onSubmit 中删除 this.props,则 URL 中的键已更改但仍位于同一页面上.从 localhost:8080/#/?_k=iwio19
到 localhost:8080/#/?_k=ldn1ew
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.
推荐答案
我不认为 routeActions
作为 props
传递.你想要做的是:
I don't 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'));
这篇关于如何使用 react-router-redux routeActions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!