react-router-dom push()函数在asyn / await动作中不可用

时间:2018-02-23 08:41:27

标签: reactjs redux async-await react-router redux-thunk

因此标题非常具有描述性,我得到的错误是:

actions.js:392 Uncaught (in promise) TypeError: (0 , _reactRouterDom.push) is not a function
    at _callee6$ (webpack:///./src/app/Army/store/actions.js?:392:49)
    at tryCatch (http://localhost:8001/vendor.js:152705:40)
    at Generator.invoke [as _invoke] (http://localhost:8001/vendor.js:152943:22)
    at Generator.prototype.(anonymous function) [as next] (http://localhost:8001/vendor.js:152757:21)
    at step (webpack:///./src/app/Army/store/actions.js?:22:191)
    at eval (webpack:///./src/app/Army/store/actions.js?:22:361)
    at <anonymous>

只是一点背景知识,我使用import 'babel-polyfill';进行asyn / await转换,我的操作如下:

export const update = (Id, Data, publish) => async (dispatch) => {
  try {
    dispatch({
      type: BA_UPDATING,
      payload: { Id },
    });

    const lib = await client.then(bfn => bfn);
    const response = await lib.getArmy(null, Data.type, Id, { ...Data, publish });

    dispatch({
      type: BA_UPDATED,
      payload: { Id, publish, response },
    });
    dispatch(push('/Army')); // ERROR.
  } catch (error) {
    dispatch({
      type: BA_ERROR,
      payload: {
        actions: 'update',
        Id,
      },
    });
  }
};

react-router-dom v4.1.1

0 个答案:

没有答案