【问题标题】:React navigation route params反应导航路线参数
【发布时间】: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


    【解决方案1】:

    问题已解决,实际上我尝试将参数从堆栈导航器传递到选项卡导航器,因此名称不匹配。另外,我也在堆栈导航器中定义了“RestaurantInfo”屏幕,所以现在我可以传递参数强文本

    【讨论】:

      猜你喜欢
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多