Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined is not an object (evaluating 'route.key') React Navigation

I am having trouble getting the stack navigator in react native to work. I am just making blank stack navigators to go inside a bottomTabsNavigator. And I get an error referring to using the route.key. Even if I make a simple Stack navigator I still get this error, and can't seem to see any mention of it online anywhere. Any help would be very appreciated :)

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
        
        

Solution was to use yarn instead of npm

like image 642
Ryan Avatar asked Dec 03 '22 17:12

Ryan


2 Answers

I had the same problem, and it was the @react-navigation/native and @react-navigation/stack versions installed. Make sure that the 2 libraries have the same version in the package.json file.

like image 181
Kaelgh Avatar answered Dec 06 '22 10:12

Kaelgh


Here you have provided the same name in the parent screen and child screens so you are getting this error to have a try with a different name in screen declarations.

like image 45
Jignesh Mayani Avatar answered Dec 06 '22 11:12

Jignesh Mayani