【问题标题】:What happens to the code that is written after execution of history push in React?在 React 中执行历史推送后编写的代码会发生什么?
【发布时间】:2021-08-30 06:28:05
【问题描述】:

我一般使用 Redirect 组件进行路由。由于我们需要返回重定向,这是可以理解的。但是,我对使用历史对象感到困惑。实际上在我的代码库中将一些路由推入历史堆栈后。有太多的动作和函数被调用。

什么时候挂载新的路由组件?如果有人看不懂,请看下面的示例代码。

const some_handler_func = () => {
  history.push('/component 2');
  setState('dummy');
  console.debug('checking') 
  //what happens to the above two lines.
}

【问题讨论】:

    标签: javascript reactjs react-router history


    【解决方案1】:

    console.debug 将按预期运行,但您的组件的状态更改可能不起作用,因为您尝试更改其状态的组件可能已卸载。

    【讨论】:

      猜你喜欢
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      • 1970-01-01
      • 2019-04-10
      • 2014-10-21
      • 1970-01-01
      • 2021-09-06
      相关资源
      最近更新 更多