我是React Native的新手。反应本机错误:
未定义不是对象(正在评估'_this2.props.navigation.navigate')
我在登录页面上遇到此错误以浏览注册页面。
login.js
import React, { Component } from 'react';
import { StatusBar, Dimensions, View, Text, TouchableOpacity,
ImageBackground, Image, TextInput } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome5'
import LinearGradient from "react-native-linear-gradient";
import { Item, Input } from 'native-base';
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from
'react-native-responsive-screen';
var { height, width } = Dimensions.get("window")
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: null,
password: null
};
}
v
render() {
return
<View style={{ flexDirection: "row", justifyContent: 'center', alignItems: 'center', marginTop: 15 }}>
<Text style={styles.hesabınText}>Hesabın yok mu? </Text>
<TouchableOpacity onPress={() => {
this.props.navigation.navigate('Register')
}} >
<Text style={{ fontFamily: "Montserrat-Bold", fontSize: 15, color: "#6DA942" }}> Kayıt Ol!
</Text>
</TouchableOpacity>
</View>
</View>;
}
}
还有我的index.js代码;
import { AppRegistry } from 'react-native';
import App from './Bottom/App'
import {createStackNavigator} from 'react-navigation'
import Login from './screen/Login';
import register from './screen/Register';
console.disableYellowBox = true;
const stack = createStackNavigator({
Login: {
screen: Login,
navigationOptions: ({ navigation }) => ({
header: null,
gestureEnabled: null
})
},
Register: {
screen: register,
navigationOptions: ({ navigation }) => ({
header: null,
gestureEnabled: null
})
},
});
AppRegistry.registerComponent('unirehberi', () => hesap );
我想在页面之间切换。我该怎么办或出现此问题的原因是什么?