[英]TypeError: undefined is not an object (evaluating '_this.props.navigation.navigate')
I'm new to react-native and I'm getting this error.我是 react-native 的新手,我收到了这个错误。 I already followed some solutions but I still get this, I also make sure that I followed tutorial properly, here's the code.
我已经遵循了一些解决方案,但我仍然得到了这个,我还确保我正确地遵循了教程,这是代码。
AppNavigation.js应用导航.js
import StackNavigator from 'react-navigation'
import Home from './Modules/Home'
const Routing = StackNavigator({
HOME: {screen: Home}
})
export default Routing
StartScreen.js开始屏幕.js
import React from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import {DotIndicator} from 'react-native-indicators';
class StartScreen extends React.Component{
switchPage = () => this.props.navigation.navigate('HOME');
render() {
return (
<View style={{backgroundColor:'#3B3C3B', flex: 1}}>
<View style={{flex: 1}}></View>
<View style={styles.container, {flex: 1}}>
<Text style={styles.text}>MY POCKET</Text>
</View>
<View style={{flex: 1}}>
<DotIndicator color='#646363'/>
<Button onPress={this.switchPage} title='Click Me'/>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
justifyContent: "center",
alignContent: "center"
},
text: {
fontSize:55,
fontWeight: "bold",
color: '#B5B5B5',
textAlign: "center"
}
})
export default StartScreen;
You must use withNavigation
.您必须使用
withNavigation
。 Like this:像这样:
import {withNavigation} from 'react-navigation'
class StartScreen extends React.Component{
// ...
}
export default withNavigation(StartScreen) // export component like this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.