reactjs – 反应 – “减速器可能不会发送行动.”导航到一条路线后

前端之家收集整理的这篇文章主要介绍了reactjs – 反应 – “减速器可能不会发送行动.”导航到一条路线后前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用
hashHistory.push('/home')

导航到我的应用程序上的某些路线.但是,每当我使用它时,我都会得到它

Reducers may not dispatch actions.

如何在不收到此错误的情况下正确导航到某条路线?

假设您正在使用Redux,您可以使用thunk中间件和react-router-redux

https://github.com/gaearon/redux-thunk

https://github.com/reactjs/react-router-redux

这将允许您分派操作,减少它,然后再发送另一个操作

import { push } from 'react-router-redux'

const someAction = (somePayload) => (dispatch,getState) => {
  dispatch({
    type: 'SOME_ACTION',payload: { 
      somePayload
    }
  });

  // Get the updated state from the store and navigate
  let { someVar } = getState();
  if (someVar === 'some value') {
    dispatch(push('/home'));
  }
};


// Call like so
store.dispatch(someAction())

如果您没有使用redux或者不想使用redux,请确保您没有在reducer中或在该操作周期的一部分内调度操作

猜你在找的React相关文章