加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 05:03:56 所属栏目:百科 来源:网络整理
导读:我正在使用 hashHistory.push('/home') 导航到我的应用程序上的某些路线.但是,每当我使用它时,我都会得到它 Reducers may not dispatch actions. 如何在不收到此错误的情况下正确导航到某条路线? 假设您正在使用Redux,您可以使用thunk中间件和react-router-
我正在使用
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中或在该操作周期的一部分内调度操作

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读