判断后端返回值正确,路由如何自动跳转

action中定义了一个请求方法:export function add(body) {  return dispatch => {
    api.add(body)
      .then(res => {        if (res.data === 200) {          // browserHistory.push('/index')
          //this.props.history.push('/index')
        }
        dispatch({          type: 'ADD_LIST',          payload: res.data
        });
      });
  }
}

把这个add方法引入页面中,在页面的点击事件直接调用:
handleSubmit = () => {  this.props.add()
}

在add方法中, 接口返回200 后,如何让路由跳转到 index 页面, if里面的2种写法都会报错, 达不到效果, 请问怎么操作,能达到效果呢? 谢谢大家!


ibeautiful
浏览 688回答 1
1回答

Cats萌萌

如果你用的是 react-router4.0, 可以看看我的这篇博客,目前我就是这么做的: 地址
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

React.JS