[英]Why am I getting 'Cannot read property 'push' of undefined' (React Native)?
In my index.ios.js, I have the following: 在我的index.ios.js中,我有以下内容:
renderScene(route, navigator){
return <route.component navigator={navigator} {...route.passProps}/>
}
and 和
render() {
return (
<Navigator
initialRoute={{name: 'FirstPage', component: FirstPage}}
renderScene={this.renderScene}
/>
);
}
then in my FirstPage.js, to navigate to the SecondPage.js: 然后在我的FirstPage.js中,导航到SecondPage.js:
_navigate(){
this.props.navigator.replace({
component: SecondPage,
name: 'SecondPage'
})
}
Then in my SecondPage.js, it just renders the component in a . 然后在我的SecondPage.js中,它只是渲染组件。 And in my ThirdPage.js:
在我的ThirdPage.js中:
_rowPressed(){
this.props.navigator.push({
component: FourthPage,
name: 'FourthPage',
})
}
<TouchableHighlight
onPress={() => this._rowPressed()}
>
<View>
<Text>Go to FourthPage</Text>
</View>
</TouchableHighlight>
Then in my FourthPage.js, I simply have: 然后在我的FourthPage.js中,我只是:
<View style={styles.container}>
This is FourthPage.js
</View>
I am getting the error from the ThirdPage.js, which says: 我从ThirdPage.js得到错误,其中说:
Cannot read property 'push' of undefined in _rowPressed()
and I cannot seem to figure out why, because the this.props.navigator.push worked fine for both .replace and .push, but now I am getting this error. 我似乎无法弄明白为什么,因为this.props.navigator.push对.replace和.push都很好,但现在我收到了这个错误。 Any guidance or insight would be appreciated.
任何指导或见解将不胜感激。 Thank you in advance.
先感谢您。
<TouchableHighlight
onPress={this._rowPressed.bind(this)}//add this
>
<View>
<Text>Go to FourthPage</Text>
</View>
</TouchableHighlight>
you may just need to bind the Component 您可能只需要绑定组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.