加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 如何使用react-router-redux routeActions?

发布时间:2020-12-15 20:48:30 所属栏目:百科 来源:网络整理
导读:我正在尝试修改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'); }}
我正在尝试修改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

谁知道怎么修它?
欣赏它.

我不认为routeActions作为道具传递.你想要做的是:
import { routeActions } from 'react-router-redux'

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读