我正在尝试修改react-router-redux的示例代码。https://github.com/rackt/react-router-redux/blob/master/examples/basic/components/Home.js https://github.com/rackt/react-router-redux/blob/master/examples/basic/components/Home.js
这是我的 Home.js
class Home extends Component {
onSubmit(props) {
this.props.routeActions.push('/foo');
}
}
我还有一个 mapDispatchToProps 。
function mapDispatchToProps(dispatch){
return bindActionCreators({ routeActions },dispatch);
}
当我调用 onSubmit 函数时,出现错误
Uncaught TypeError: this.props.routeActions.push is not a function
如果我在 onSubmit 中删除 this.props,URL 中的键会更改,但它仍然在同一页面上。
从localhost:8080/#/?_k=iwio19
to localhost:8080/#/?_k=ldn1ew
谁知道怎么修它?
欣赏它。
我不认为routeActions
被传递为props
。你想做的是这样的:
import { routeActions } from 'react-router-redux'
this.props.dispatch(routeActions.push('/foo'));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)