【发布时间】:2022-10-24 18:26:27
【问题描述】:
我是 React Native 的新手,我正在尝试使用“导航/菜单栏”,但出现以下错误
Unable to resolve "@react-navigation/drawer" from "App.js"
我安装了但仍然出现同样的错误,我错在哪里?这是我的代码 这是我当前的代码
import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
onPress={() => navigation.navigate('Notifications')}
title="Go to notifications"
/>
</View>
);
}
function NotificationsScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button onPress={() => navigation.goBack()} title="Go back home" />
</View>
);
}
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}
【问题讨论】:
-
@GauravRoy:是什么意思?我怎样才能分享这个?
-
像世博小吃是一个网站,您可以在其中共享代码的工作示例,p 租赁共享
-
@GauravRoy:当然,先生,那么请给我几分钟
标签: reactjs react-native