在我的index.ios.js中,我有以下内容:
renderScene(route, navigator){
return <route.component navigator={navigator} {...route.passProps}/>
}
和
render() {
return (
<Navigator
initialRoute={{name: 'FirstPage', component: FirstPage}}
renderScene={this.renderScene}
/>
);
}
然后在我的FirstPage.js中,导航到SecondPage.js:
_navigate(){
this.props.navigator.replace({
component: SecondPage,
name: 'SecondPage'
})
}
然后在我的SecondPage.js中,它只是将组件呈现在。在我的ThirdPage.js中:
_rowPressed(){
this.props.navigator.push({
component: FourthPage,
name: 'FourthPage',
})
}
<TouchableHighlight
onPress={() => this._rowPressed()}
>
<View>
<Text>Go to FourthPage</Text>
</View>
</TouchableHighlight>
然后在我的FourthPage.js中,我只需要:
<View style={styles.container}>
This is FourthPage.js
</View>
我从ThirdPage.js得到错误,它说:
Cannot read property 'push' of undefined in _rowPressed()
我似乎找不出原因,因为this.props.navigator.push在.replace和.push上都工作得很好,但现在我得到了这个错误。任何指导或见解都将不胜感激。提前谢谢你。
发布于 2016-07-15 02:51:50
<TouchableHighlight
onPress={this._rowPressed.bind(this)}//add this
>
<View>
<Text>Go to FourthPage</Text>
</View>
</TouchableHighlight>
您可能只需要绑定组件
https://stackoverflow.com/questions/38379656
复制相似问题