我将在我的项目中设计一个抽屉导航。
我通过以下命令安装了该命令:
npm install @react-navigation/drawer
然后将其导入 App.js
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
这是我的package.json
内容:
"@react-native-community/masked-view": "^0.1.6",
"@react-navigation/drawer": "^5.0.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.5.6",
"react-native-reanimated": "^1.7.0",
"react-native-screens": "^2.0.0-beta.1",
"react-native-view-shot": "^3.0.2",
"react-navigation": "^4.1.1",
"react-navigation-stack": "^2.1.0",
这是我的App.js
内容:
const App = () => {
const Drawer = createDrawerNavigator();
return (
<View style={styles.container}>
<NavigationContainer>
<Drawer.Navigator initialRouteName="login">
<Drawer.Screen name="login" component={Login} />
<Drawer.Screen name="second" component={SecondPage} />
</Drawer.Navigator>
</NavigationContainer>
</View>
)
};
我应该说我已经创建Login
和SecondPage
组件,并在一个名为文件中声明他们root.js
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { Login, Header, SecondPage, Footer, ThirdPage } from './components/index';
const AppNavigator = createStackNavigator({
login: { screen: Login },
header: { screen: Header },
second: { screen: SecondPage },
footer: { screen: Footer },
third: { screen: ThirdPage }
}, {
initialRouteName: 'login',
headerMode: 'none',
mode: 'modal',
}, {});
export default createAppContainer(AppNavigator);
但是我收到一个错误(以下屏幕)。
我怎样才能解决这个问题?
index.js
export * from './login';
export * from './header';
export * from './secondpage';
export * from './footer';
export * from './thirdpage';