undefined不是一个对象(评估“route.key”)ReactNavigation
我无法让堆栈导航器响应本机工作。我只是制作空白堆栈导航器以进入bottomTabsNavigator。我收到一个关于使用 route.key 的错误。即使我制作了一个简单的 Stack 导航器,我仍然会收到此错误,并且似乎在网上的任何地方都看不到任何提及。任何帮助将不胜感激:)
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack';
import Icon from 'react-native-vector-icons/MaterialIcons';
import CartScreen from './screens/CartScreen'
import RecipeScreen from './screens/RecipeScreen'
import ProfileScreen from './screens/ProfileScreen'
const Stack = createStackNavigator();
function Navigator() {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={({ route }) => ({
headerStyle: {
backgroundColor: 'salmon',
},
headerTintColor: 'white',
headerTitleStyle: {
fontWeight: 'bold',
},
})}
tabBarOptions={{
showLabel: false,
activeTintColor: 'white',
inactiveTintColor: 'pink',
style: {backgroundColor: 'salmon', height: 60,}
}}
>
<Stack.Screen name="cart" component={CartScreen} />
<Stack.Screen name="recipe" component={RecipeScreen} />
<Stack.Screen name="profile" component={ProfileScreen} />
</Stack.Navigator>
</NavigationContainer>
)
}
export default Navigator
解决方案是使用 yarn 而不是 npm
回答
我遇到了同样的问题,它是安装了 @react-navigation/native 和 @react-navigation/stack 版本。确保 2 个库在 package.json 文件中具有相同的版本。
THE END
二维码