TypeError: undefined 不是对象(评估 '_this.props.navigation.navigate')



我是新来的本地react,我收到了这个错误。我已经遵循了一些解决方案,但我仍然得到了这个,我也确保我正确地遵循了教程,这是代码。

AppNavigation.js

import StackNavigator from 'react-navigation'
import Home from './Modules/Home'
const Routing = StackNavigator({
HOME: {screen: Home}
})
export default Routing

StartScreen.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;

您必须使用withNavigation。像这样:

import {withNavigation} from 'react-navigation'
class StartScreen extends React.Component{
// ...
}
export default withNavigation(StartScreen) // export component like this

最新更新