Reactjs react中的history.push()是异步调用吗?

Reactjs react中的history.push()是异步调用吗?,reactjs,react-router,Reactjs,React Router,我正在使用reducer中react提供的历史对象(从组件传递到reducer),在更新状态时有条件地路由到其他页面。 我知道这不是导航必须处理的方式。 但是它仍然在工作,这就是history.push()函数的异步调用 在reducer中返回修改状态之前执行它。 有人能解释一下为什么这样做吗 const reducer = (state = initialState, action) => { var stateClone = {...state}; switch(action.type

我正在使用reducer中react提供的历史对象(从组件传递到reducer),在更新状态时有条件地路由到其他页面。 我知道这不是导航必须处理的方式。 但是它仍然在工作,这就是history.push()函数的异步调用 在reducer中返回修改状态之前执行它。 有人能解释一下为什么这样做吗

const reducer = (state = initialState, action) => {
var stateClone = {...state};
switch(action.type)
{
  case 'LogIn':
  var user = state.users.filter((user) => user.userName === action.userName && user.password === action.password );
  if(user.length > 0 )
  {
    var loggedInUser = {...user[0]};
    stateClone.loggedInUser = loggedInUser;
    action.history.push('/products');
    return stateClone;
  }
  else {
    alert('Wrong Credentials');
  }
  return state;
}
}

是的,这是一个异步调用。查看此项。

历史记录。推送可能是同步的,但可能以异步方式影响应用程序。首先,减速机不应该包含副作用。