[React Native, RN]类型错误:未定义不是对象(评估"route.params")


import React, {useState, Component, useMemo} from 'react';
import { StyleSheet, Text, View, Button, TextInput, Image } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage'
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();
function GameScreen({   navigation, route  }){
const [name, setName] = useState('이화연');
return(
<View style={{paddingTop:10}}>
<View style={{flexDirection:"column"}}>
<Text style={text_st}>당신의 이름을 알려 주세요.</Text>
<TextInput style={input_st}
onChangeText={setName}
value={name}
maxLength={10}/>
<Button title="확인"
color= {EwhaGreen}
onPress={function(){navigation.navigate('1',
{ params: name } )}} />
</View>
</View>
);
};
function GameScreen_1({ navigation }, {route}){
var N = route.params.name
return(
<View style={{alignItems:'center', justifyContent:'center'}}>
<View style={{margin:5}}></View>
<div>
<Text>{N}, 일어나!</Text>
</div>
<Text>눈을 떠 보니 여기는...?</Text>
<View style={{margin:5}}></View>
<Image style={{width:500, height:500}} source={require('./assets/1.jpg')} />
<View style={{margin:10}}></View>
<Button title="이화여대?"
color= {EwhaGreen}
onPress={function(){navigation.navigate('2') }} />
</View>
);
};

我想在函数GameScreen_1中使用常量名称。但我得到的只是一个错误代码"TypeError:undefined不是对象(正在评估"route.params"("请帮帮我。我花了很多天的时间来解决这个问题。

应该是

function GameScreen_1({ navigation, route})

您已将其放置在另一个Curley括号内。

您的函数体应该看起来像

function GameScreen_1({ route, navigation }){

这是文档https://reactnavigation.org/docs/params/

相关内容

最新更新