首页 > 解决方案 > 未定义的'_this2.props.navigation.navigate'

问题描述

我有问题,我想从 Modal 中的登录导航到注册。这个问题是怎么解决的?

我如何才能在模态中导航?

在此处输入图像描述

在此处输入图像描述

import React, { Component } from 'react';
import { Alert, StyleSheet, Text, TouchableOpacity, View, Dimensions, TextInput } from 'react-native';
import Modal from 'react-native-modalbox';
import Lock from '../../../assets/icon/lock.svg';
import User from '../../../assets/icon/user.svg';

var screen = Dimensions.get('window');
class Login extends Component {
    constructor(props) {
        super(props);
    }

    showLogin = () => {
        this.refs.myLogin.open();
    }

    closeLogin = () => {
        this.refs.myLogin.close();
    }

    render() {
        return (
            <Modal
                ref={"myLogin"}
                style={{
                    borderRadius: 10,
                    width: screen.width - 80,
                    shadowRadius: 10,
                    height: 300,
                }}
                position='center'
                backdrop={true}
            />
        )
    }
}

和这个按钮

<TouchableOpacity onPress={() => this.props.navigation.navigate('Register')}>
    <Text style={{ color: '#024379', fontWeight: 'bold' }}>Daftar Disini</Text>
</TouchableOpacity>

标签: react-nativereact-navigation

解决方案


使用withNavigationHOC 能够访问组件中的导航道具。

参考请看这个


推荐阅读