【发布时间】:2022-01-16 04:16:48
【问题描述】:
我是 react-native 的新手。为了学习,我创建了一个示例项目。我想通过按抽屉内的文本导航到另一个页面。所以我面临一个错误
TypeError: undefined is not an object (evaluating '_this.props.navigation.navigate')
我添加了示例代码
import React,{Component} from "react";
import { StyleSheet, Text, View ,ImageBackground,} from "react-native";
export default class DrawerContent extends Component{
render(){
return(
<View style={Styles.container}>
<ImageBackground source={require('../../assets/drawerbg.jpg')}>
<Text style={Styles.TextFiled}
onPress = {()=> this.props.navigation.navigate('Home')}>Home</Text>
<Text style={Styles.TextFiled}
onPress = {()=> this.props.navigation.navigate('Profile')}>Profile</Text>
<Text style={Styles.TextFiled}
onPress = {()=> this.props.navigation.navigate('Settings')}>Settings</Text>
</ImageBackground>
</View>
)
}
}
【问题讨论】:
标签: reactjs react-native react-navigation jsx react-navigation-drawer