react 在判断接口返回值正确后让路由自动跳转

在actions中,定义了一个方法去调用接口,然后在页面中调用actions中定义的方法,当actions方法成功请求接口后,如何自动跳转到指定的path,

在actions中写过this.props.history.push(""),然后报history undefined,然后试过很多写法,都不能达到效果,请大家帮帮忙,出出主意,非常感谢


繁花不似锦
浏览 1867回答 2
2回答

慕侠2389804

方法调用使用方法名.bind(this, 参数)方式,更改this指向

繁华开满天机

先引入import { Link, withRouter } from "react-router-dom";再包装const Component = withRouter(createForm()(_Component));这样history就不会报undefined了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

React.JS