【发布时间】:2020-03-22 01:15:40
【问题描述】:
我正在尝试使用导航方法将变量从页面传递到另一个页面,但是当我尝试如下所示读取它时,我得到 getParam() 方法未定义。我没有使用类。
这是我传递变量的第一页
const handleBarCodeScanned = ({ type, data }) => {
setScanned(true);
//alert(`Bar code with type ${type} and data ${data} has been scanned!`);
splitted = data.split('=');
invitationFromURL=splitted[1];
navigation.navigate('HomeScreen',{text:invitationFromURL});
//console.log('Invite '+splitted[1]);
};
这是我收到变量的主页
import { Image, Platform, StyleSheet, Text, TouchableOpacity, View, Button,Alert } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
//import { IconButton, Colors } from 'react-native-paper';
import * as WebBrowser from 'expo-web-browser';
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
//import { BarCodeScanner } from 'expo-barcode-scanner';
import { MonoText } from '../components/StyledText';
export default function HomeScreen(props) {
const { navigation } = props
const text = navigation.getParams ('text','nothing sent');
我得到的错误
**
navigation.getParams 不是函数。 (在 'navigation.getParams('text', 'nothing sent')' 中,'navigation.getParams' 未定义)**
【问题讨论】:
标签: react-native navigation expo