React4.0路由跳转

1,使用this.context.router.history.push(’/orderDetail’)
代码如下:

import PropTypes from "prop-types";
class List extends Component{
  static contextTypes = {
    router: PropTypes.object
  }
constructor(props,context) {
    super(props,context);
    this.state = {};
}

handleItemClick(){//点击事件
this.context.router.history.push('/orderDetail')
}


2,官方推荐:

import {withRouter} from "react-router-dom";
class List extends Component{
constructor(props) {
    super(props);
    this.state = {};
}

handleItemClick(){//点击事件
this.props.history.push("/orderDetail");
}


参考链接https://github.com/brickspert/blog/issues/3

猜你喜欢

转载自blog.csdn.net/etemal_bright/article/details/88655087
今日推荐