React Native 导航路线到导航栏中未列出的屏幕?

问题描述 投票:0回答:1

我想通过我的平面列表路由到名为“聊天”的屏幕。我尝试了

useNavigation()
,但在世博会上我得到了
ERROR: The action 'NAVIGATE' with payload {"name":"Chat","params":{"id":3}} was not handled by any navigator.
。我还尝试将其包装在来自
createNativeStackNavigator
@react-navigation/native-stack
中,但这也不起作用,因为然后我有两个孩子传递到导航项中。

// Chat list screen

import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { Text, View, Image, SafeAreaView, FlatList, TouchableHighlight } from 'react-native';
import { useNavigation } from '@react-navigation/native';

const ChatListScreen = ({}) => {
    const navigation = useNavigation();
    return (
        <SafeAreaView className="container mx-auto max-w-screen-xl">
            <FlatList className="my-4 px-4"
                data={users}
                renderItem={({ item }) =>   
                    <TouchableHighlight onPress={() => navigation.navigate('Chat', { id: item.id })}>
                        <Item username={item.username} avatar={item.avatar} lastMessage={item.lastMessage} id={item.id}/>
                    </TouchableHighlight>
                }
                keyExtractor={item => item.id}
            />
        </SafeAreaView >
    );
}

export default ChatListScreen;
javascript reactjs react-native expo react-navigation
1个回答
0
投票

根据评论,您可以尝试在导航器中隐藏屏幕

Chat

    <Drawer.Screen name="Chat" component={Chat}
        options={{drawerItemStyle: { display: 'none' }}}
    />

上面只是一个例子,但是看了一个旧项目……我就是这样做的。

© www.soinside.com 2019 - 2024. All rights reserved.