错误:无法注册导航器。您是否使用“NavigationContainer”包装了您的应用程序?
我正在学习使用此视频https://youtu.be/1hPgQWbWmEk进行编码,我完全按照那个人所做的去做,但是当我运行expo start然后在 Web 浏览器中运行时,会出现以下错误:
无法注册导航器。您是否使用“NavigationContainer”包装了您的应用程序?
到目前为止,这是我的代码
import { StatusBar } from 'expo-status-bar';
import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {navigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs'
import LandingScreen from './Components/auth/landing';
const Stack = createStackNavigator();
export default function App() {
return (
<navigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen name="Landing" component={LandingScreen} options={{headerShown: false}}/>
</Stack.Navigator>
</navigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
回答
您的代码中有一个拼写错误,它必须是NavigationContainer而不是navigationContainer.
import { NavigationContainer } from '@react-navigation/native';
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen name="Landing" component={LandingScreen} options={{headerShown: false}}/>
</Stack.Navigator>
</NavigationContainer>
);
}
THE END
二维码