简体   繁体   English

类型错误:未定义不是对象(评估“_this.props.navigation.navigate”)

[英]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.

相关问题 TypeError: undefined is not an object (evalating '_this.props.navigation.navigate') reactNavigation 5 - TypeError: undefined is not an object (evaluating '_this.props.navigation.navigate') reactNavigation 5 未定义不是对象(评估this.props.navigation.navigate) - undefined is not an object (evaluating this.props.navigation.navigate) 未定义不是对象(评估&#39;_this.props.navigation.navigate&#39;) - undefined is not an object (evaluating '_this.props.navigation.navigate') ERROR TypeError: undefined is not an object (evalating 'this.props.navigation.navigate') when import my component in child - ERROR TypeError: undefined is not an object (evaluating 'this.props.navigation.navigate') when import my component in child 错误:未定义不是 object(评估 this.props.navigation.navigate) - Error: undefined is not an object (evaluating this.props.navigation.navigate) 类型错误:未定义不是对象(评估 this.props.navigation.navigate) - Type Error: Undefined is not an object (evaluating this.props.navigation.navigate) 使用开关导航器:对象(评估&#39;_this.props.navigation.navigate&#39;)未定义 - using switch navigator: object (evaluating '_this.props.navigation.navigate') undefined 未定义不是组件上的对象(评估“ this.props.navigation.navigate”) - undefined is not an object (evaluating 'this.props.navigation.navigate') on a component 创建导航器时,未定义不是 object(评估 this.props.navigation.navigate) - Undefined is not an object (evaluating this.props.navigation.navigate) when creating navigator 【React-native】undefined不是对象(评估&#39;_this.props.navigation.navigate&#39;) - 【React-native】undefined is not an object (evaluating '_this.props.navigation.navigate')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM