【发布时间】:2021-04-26 14:13:32
【问题描述】:
我正在使用反应导航并希望将参数 id 传递到我的屏幕 RestaurantInfo 但是当我在该屏幕中控制台登录 id 时显示“未定义” 即使遵循他们以类似方式完成的文档,如何正确传递参数
参数代码:-
const renderItem = ({ item }) => {
return (
<TouchableOpacity style={{ flex: 1 }} key={item.id} onPress={() => navigation.navigate(
"RestaurantInfo",
{
id: 1
}
)}>
<Card style={{ flex: 1 }}>
<Card.Title >{item.name}</Card.Title>
<Card.Title>{item.id}</Card.Title>
<Card.Image
source={{ uri: "https://static.toiimg.com/photo/72975551.cms" }}
resizeMode="cover" ></Card.Image>
{/* <Text>
<Icon
name='email' />
Email</Text>
<Text> */}
<Card.Divider></Card.Divider>
</Card>
</TouchableOpacity>
)
}
屏幕代码:-
import React from 'react'
import { View, Text } from 'react-native'
export const restaurantInfo = ({ route, navigation }) => {
console.log(route);
return (
<View>
<Text>Restaurant Info</Text>
</View>
)
}
输出:-
Object {
"key": "restaurantMenu-u_fPFgzRQgEIhM9l1TDtt",
"name": "restaurantMenu",
"params": undefined,
}
【问题讨论】:
标签: reactjs react-native parameters frontend react-navigation