首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我得到'Cannot read property 'push‘of undefined’(React Native)?

为什么我得到'Cannot read property 'push‘of undefined’(React Native)?
EN

Stack Overflow用户
提问于 2016-07-15 00:35:59
回答 1查看 1.7K关注 0票数 4

在我的index.ios.js中,我有以下内容:

代码语言:javascript
运行
复制
  renderScene(route, navigator){
    return <route.component navigator={navigator} {...route.passProps}/>
  }

代码语言:javascript
运行
复制
render() {
    return (
      <Navigator
        initialRoute={{name: 'FirstPage', component: FirstPage}}
        renderScene={this.renderScene}
      />
    );
  }

然后在我的FirstPage.js中,导航到SecondPage.js:

代码语言:javascript
运行
复制
  _navigate(){
    this.props.navigator.replace({
      component: SecondPage,
      name: 'SecondPage'
    })
  }

然后在我的SecondPage.js中,它只是将组件呈现在。在我的ThirdPage.js中:

代码语言:javascript
运行
复制
  _rowPressed(){
    this.props.navigator.push({
      component: FourthPage,
      name: 'FourthPage',
    })
  }


  <TouchableHighlight
    onPress={() => this._rowPressed()}
  >
     <View>
          <Text>Go to FourthPage</Text>
     </View>
  </TouchableHighlight>

然后在我的FourthPage.js中,我只需要:

代码语言:javascript
运行
复制
  <View style={styles.container}>
    This is FourthPage.js
  </View>

我从ThirdPage.js得到错误,它说:

代码语言:javascript
运行
复制
Cannot read property 'push' of undefined in _rowPressed()

我似乎找不出原因,因为this.props.navigator.push在.replace和.push上都工作得很好,但现在我得到了这个错误。任何指导或见解都将不胜感激。提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2016-07-15 02:51:50

代码语言:javascript
运行
复制
<TouchableHighlight
    onPress={this._rowPressed.bind(this)}//add this
  >
     <View>
          <Text>Go to FourthPage</Text>
     </View>
  </TouchableHighlight>

您可能只需要绑定组件

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38379656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档