javascript - 不变违规 : Calling pop to route for a route that doesn't exist

标签 javascript reactjs react-native

我正在使用 NavigatorIOS,当我传递给初始路由的 Prop 发生变化时,我试图通过重置为您在下面使用“componentWillReceiveProps”中新更新的 Prop 找到的组件来更新它们。

    componentWillReceiveProps: function(nextProps) {
      this.refs.navigator.resetTo({
                    title: 'Home',
                    component: search,
                    backButtonTitle: 'Back',
                    passProps: {
                      api: nextProps.api,
                      slug: nextProps.slug
                   }
      });
    }

我很确定我没有正确引用路线,但坦率地说,我还没有找到任何关于这个问题的有用资源。

Replace() 完成更新 Prop 的工作,但我也希望它到 popToTop()。 Replace 和 ResetTo 都采用路由对象,所以我不明白为什么 replace() 有效并且 resetTo() 给我这个错误。

这是我的 NavigatorIOS:

      <NavigatorIOS
            ref='navigator'
            initialRoute={
            {
              title: 'Home',
              component: search,
              backButtonTitle: 'Back',
                    passProps: {
                        api: this.props.api,
                        slug: this.props.slug
                     }

             }
           }
    />

enter image description here

最佳答案

如果你声明如下:

var routes = this.refs.navigator.getCurrentRoutes();

然后你可以像这样弹出一个路由:

this.refs.navigator.popToRoute(routes[1]);

关于javascript - 不变违规 : Calling pop to route for a route that doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31320583/

相关文章:

javascript - 无法在 javascript jQuery 中读取 PHP 结构数组

javascript - Canvas DataURL 到带有 filePath 的图像

javascript - 如何更改 Flatlist react native 中的 textInput 值?

javascript - 简单的 for 循环让我陷入循环 - 小数增量错误

javascript - 如何按 es6/React 中的特定字段对 map 进行排序?

javascript - 如何在服务器端渲染ES6方式上管理React组件?

ReactJS Material-UI 如何设置始终覆盖文本字段的自动完成样式

node.js - watchman.plist 权限在运行 react-native 初始项目时被拒绝

javascript - 在 index、js 和 app.js 中 react native 错误

javascript - 如何分离嵌套的异步函数并按所需顺序执行它们?