React native 如何将值(例如登录数据)传递到react navigation 5中的profile中?

React native 如何将值(例如登录数据)传递到react navigation 5中的profile中?,react-native,React Native,在react导航中,我无法将用户名值和其他数据等值传递到配置文件屏幕。假设我有这样的登录页面和个人资料页面 Login.js export default class LoginScreen extends Component { constructor(props) { super(props) this.state = { username: '', password: '' } } _login = async () => {

在react导航中,我无法将用户名值和其他数据等值传递到配置文件屏幕。假设我有这样的登录页面和个人资料页面

Login.js

export default class LoginScreen extends Component {
constructor(props) {
    super(props)
    this.state = {
        username: '',
        password: ''
    }
}

_login = async () => {
    if (userInfo.username == this.state.username && userInfo.password == this.state.password) {
        await AsyncStorage.setItem('isLoggedIn', '1');
        this.props.navigation.navigate('HomeApp',{
            Username: 'Deni'
        });
    } else {
        alert('Password kamu salah')
    }
}
....
以及Profile.js如何获取数据。我已经尝试过getParam,this.props.navigation.getParams,它们都不起作用或抛出错误。请帮忙,谢谢

我曾尝试在react导航示例中使用此方法。。但还是失败了。其所述路由未定义或参数未定义

const { itemId } = route.params;
  const { otherParam } = route.params;
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Details Screen</Text>
      <Text>itemId: {JSON.stringify(itemId)}</Text>
      <Text>otherParam: {JSON.stringify(otherParam)}</Text>
      <Button
        title="Go to Details... again"
        onPress={() =>
          navigation.push('Details', {
            itemId: Math.floor(Math.random() * 100),
          })
const{itemId}=route.params;
const{otherParam}=route.params;
返回(
详细信息屏幕
itemId:{JSON.stringify(itemId)}
otherParam:{JSON.stringify(otherParam)}
navigation.push('Details'{
itemId:Math.floor(Math.random()*100),
})

这是类组件吗?对于函数组件,请使用
const Profile=({route,navigation})=>…
您使用的是this.props.route吗?它是一个屏幕组件吗?添加您访问路由的方式。@juniues,实际上我在配置文件中使用类组件,不知何故,我应该将其更改为函数组件。是否有其他方法用作类组件。我还是新手。。请帮助