【问题标题】:Handle page refreshes when you're using React router使用 React 路由器时处理页面刷新
【发布时间】:2016-05-03 23:20:34
【问题描述】:

问题: 当我最初访问根 URL 时,路由器会呈现正确的页面。导航也可以正常工作。但是,当我点击refresh 时,应用程序崩溃并出现以下错误:

instrument.js:112 Uncaught TypeError: Cannot read property 'length' of undefined

这是instrument.js:112 中的函数。 computedStatesundefined

/**
 * Runs the reducer on invalidated actions to get a fresh computation log.
 */
function recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds) {
  // Optimization: exit early and return the same reference
  // if we know nothing could have changed.
  if (minInvalidatedStateIndex >= computedStates.length && computedStates.length === stagedActionIds.length) {
    return computedStates;
  }

当我执行localStorage.clear() 并刷新页面时,应用又回来了。

可能导致该问题的软件包:

"react-router": "^2.0.0",
"react-router-redux": "^4.0.0",
"redux-localstorage": "^0.4.0",

使用 react 路由器时处理页面刷新的最佳方式是什么?

【问题讨论】:

    标签: reactjs react-router redux


    【解决方案1】:

    根据我的经验,React Router 在页面刷新方面没有问题。听起来您可能在本地存储进入刷新页面时出现问题的状态时遇到问题。我建议您在最初加载页面后检查本地存储的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-17
      • 2021-12-13
      • 1970-01-01
      • 2020-12-08
      • 2019-01-12
      • 2017-10-06
      • 2015-12-09
      • 1970-01-01
      相关资源
      最近更新 更多