Javascript 首次尝试时,this.props.history.push不会重定向

Javascript 首次尝试时,this.props.history.push不会重定向,javascript,node.js,reactjs,redux,mern,Javascript,Node.js,Reactjs,Redux,Mern,我们正在尝试在获得搜索结果后重定向到搜索结果页面。我们正在使用axios.get()发送get请求,如下所示: export const searchPosts = (type, query) => async dispatch => { dispatch({ type: PARTIAL_LOADING, payload: false }); const res = await axios.get('/api/search/', { para

我们正在尝试在获得搜索结果后重定向到搜索结果页面。我们正在使用axios.get()发送get请求,如下所示:

export const searchPosts = (type, query) => async dispatch => {
    dispatch({ type: PARTIAL_LOADING, payload: false });

    const res = await axios.get('/api/search/',
    {
        params: {
            type: type,
            query: query
    }});

    dispatch({ type: PARTIAL_LOADING, payload: true });

    dispatch({
        type: SEARCH,
        payload: res.data
    });
};
我们正在尝试使用以下命令重定向到下一页:

async submitSearch(values) {
  const type = values.type ? values.type : "Default";
  const query = values.query;

  if (type && query)
  {
    await this.props.searchPosts(type, query)
    .then(_ => {
      this.props.history.push('/search_results');
    });
  }
}

这会在第一次尝试后重定向,但第一次总是会失败。

您可以同时使用
wait
吗?这是如何工作的?一旦你获得了成功获取请求的数据,你就无法路由到搜索结果组件,这是问题吗?@DILEEPTHOMAS我们不能,这就是问题所在。