react-native - React Native Stack 导航屏幕不存在
问题描述
在 App.js 我有以下堆栈导航器:
<NavigationContainer>
<Stack.Navigator>
{user ? (
<Stack.Screen name="Home">
{(props) => <HomeScreen {...props} extraData={user} />}
</Stack.Screen>
) : (
<>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Registration" component={RegistrationScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
在主屏幕中,我试图导航到“个人资料”屏幕:
export default function HomeScreen(props) {
const onProfilePress = () => {
props.navigation.navigate('Profile')
};
return (
<View style={styles.container}>
<TouchableOpacity style={styles.button} onPress={onProfilePress}>
<Text style={styles.buttonText}>Profile</Text>
</TouchableOpacity>
</View>
);
}
但是,我得到一个
The action 'NAVIGATE' with payload {"name":"Profile"} was not handled by any navigator.
有谁知道如何解决?
解决方案
Profile
user
当为真时,它只是堆栈的一部分。也许你打算做这样的事情:
<NavigationContainer>
<Stack.Navigator>
{user ? (
<>
<Stack.Screen name="Home">
{(props) => <HomeScreen {...props} extraData={user} />}
</Stack.Screen>
<Stack.Screen name="Profile" component={ProfileScreen} />
</>
) : (
<>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Registration" component={RegistrationScreen} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
推荐阅读
- hive - 从文件中直线运行查询
- scheduled-tasks - Java EE 7 在不同的环境/层中调度任务
- python - 如何使用 Beautiful Soup 在 Python 中复制和替换元素及其子元素?
- java - 如何制作一种方法来检查一个事件是否与一个人注册的另一个事件重叠?
- angular - Angular 4相同的路线不同的组件与警卫
- react-native - 平面列表 android 动画无法按预期工作
- puppeteer - 如何在 puppeteer 中设置标头只是主页请求而不是所有请求
- c# - 如何读取表格并将其从 pdf 转换为 xml/html?
- mysql - Laravel Eloquent 查询预订
- python - pyscripter 在启动时崩溃