我正在尝试修改react-router-redux的示例代码。 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到localhost:8080/#/?_k=ldn1ew
localhost:8080/#/?_k=iwio19
localhost:8080/#/?_k=ldn1ew
谁知道怎么修它?欣赏它。
我认为routeActions不会通过props。您要做的是:
routeActions
props
import { routeActions } from 'react-router-redux' this.props.dispatch(routeActions.push('/foo'));