Claude Skills Guide

Claude Code for React Native Navigation Setup Guide

Setting up navigation in React Native can be one of the most challenging aspects of mobile app development, especially when you’re trying to choose between the various navigation libraries and configure them correctly. This guide shows you how to use Claude Code to streamline your React Native navigation setup, from choosing the right navigation library to implementing complex navigation patterns with confidence.

Understanding React Native Navigation Options

Before diving into the setup, it’s important to understand the navigation ecosystem in React Native. The two primary options you’ll encounter are React Navigation (the most popular choice) and React Native Navigation (Wix’s solution). For most projects, React Navigation is the recommended approach due to its flexibility, active maintenance, and strong community support.

React Navigation offers several navigation types: Stack Navigator for hierarchical screen flows, Tab Navigator for bottom navigation, Drawer Navigator for side menus, and the ability to nest these navigators together. Claude Code can help you understand which combination suits your app’s user experience goals.

When to Use Each Navigation Type

Stack Navigator works best for linear flows where users move through screens in sequence, like authentication flows or checkout processes. Tab Navigator excels when you have multiple top-level sections that need equal prominence, such as home, profile, and settings. Drawer Navigator suits apps with many sections or when you want to maximize screen real estate by hiding navigation behind a gesture.

Setting Up React Navigation with Claude Code

Let’s walk through the complete setup process. Claude Code can guide you through each step, but understanding the foundation helps you provide better context.

Installation

First, install the core navigation packages:

npm install @react-navigation/native @react-navigation/native-stack
npm install react-native-screens react-native-safe-area-context

The first command installs the navigation core and stack navigator. The second installs peer dependencies that React Navigation needs to function correctly on both iOS and Android. If you plan to use tabs or drawer navigation, you’ll need additional packages:

npm install @react-navigation/bottom-tabs
npm install @react-navigation/drawer

Basic Stack Navigation Setup

Create a simple stack navigator to understand the fundamentals:

import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { HomeScreen } from './screens/HomeScreen';
import { DetailsScreen } from './screens/DetailsScreen';

const Stack = createNativeStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen 
          name="Home" 
          component={HomeScreen}
          options={{ title: 'Welcome Home' }}
        />
        <Stack.Screen 
          name="Details" 
          component={DetailsScreen}
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

This basic setup creates a stack with two screens. The NavigationContainer wraps your entire app and provides the navigation context. Each Stack.Screen represents a screen in your app, with the name property serving as a unique identifier for navigation.

Configuring Stack Navigator Options

Customize the navigation experience with various options:

<Stack.Navigator
  screenOptions={{
    headerStyle: {
      backgroundColor: '#f4511e',
    },
    headerTintColor: '#fff',
    headerTitleStyle: {
      fontWeight: 'bold',
    },
    animation: 'slide_from_right',
  }}
>

These options apply to all screens in the stack. You can also set options on individual screens, which override the navigator defaults.

Implementing Tab Navigation

Tab navigation provides persistent bottom navigation that’s intuitive for many mobile apps.

Setting Up Bottom Tabs

import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { HomeScreen } from './screens/HomeScreen';
import { SettingsScreen } from './screens/SettingsScreen';
import { Ionicons } from '@expo/vector-icons';

const Tab = createBottomTabNavigator();

function TabNavigator() {
  return (
    <Tab.Navigator
      screenOptions={({ route }) => ({
        tabBarIcon: ({ focused, color, size }) => {
          let iconName: keyof typeof Ionicons.glyphMap;

          if (route.name === 'Home') {
            iconName = focused ? 'home' : 'home-outline';
          } else if (route.name === 'Settings') {
            iconName = focused ? 'settings' : 'settings-outline';
          }

          return <Ionicons name={iconName} size={size} color={color} />;
        },
        tabBarActiveTintColor: '#f4511e',
        tabBarInactiveTintColor: 'gray',
      })}
    >
      <Tab.Screen name="Home" component={HomeScreen} />
      <Tab.Screen name="Settings" component={SettingsScreen} />
    </Tab.Navigator>
  );
}

Combining Stack and Tab Navigation

Most apps combine multiple navigation types. A common pattern is having tabs at the top level with stacks within each tab:

function RootNavigator() {
  return (
    <Stack.Navigator>
      <Stack.Screen name="Login" component={LoginScreen} />
      <Stack.Screen name="Main" component={TabNavigator} />
    </Stack.Navigator>
  );
}

This pattern lets you have a login flow that sits outside the main app navigation, while the tabs provide the primary navigation within the authenticated experience.

Advanced Navigation Patterns

Passing Parameters Between Screens

Navigate with parameters using the params object:

// Navigation
navigation.navigate('Details', { 
  itemId: 42, 
  itemName: 'Product Name' 
});

// Receiving parameters
function DetailsScreen({ route }) {
  const { itemId, itemName } = route.params;
  return <Text>Item: {itemName} (ID: {itemId})</Text>;
}

TypeScript Typing for Navigation

Type your navigation for better developer experience:

type RootStackParamList = {
  Home: undefined;
  Details: { itemId: number; itemName: string };
  Profile: { userId: string };
};

const Stack = createNativeStackNavigator<RootStackParamList>();

With TypeScript typing, you’ll get autocomplete for route names and parameters, reducing runtime errors significantly.

Configure deep linking to handle external URLs:

const linking = {
  prefixes: ['https://myapp.com', 'myapp://'],
  config: {
    screens: {
      Home: 'home',
      Details: 'details/:itemId',
    },
  },
};

function App() {
  return (
    <NavigationContainer linking={linking}>
      <Stack.Navigator>
        {/* screens */}
      </Stack.Navigator>
    </NavigationContainer>
  );
}

Common Navigation Issues and Solutions

If your navigation state isn’t updating as expected, ensure you’re using the correct navigation hook. The useNavigation hook provides access to the navigation object, while useRoute accesses the current route’s params.

Performance Concerns

For large apps, consider lazy loading screens:

const DetailsScreen = lazy(() => import('./screens/DetailsScreen'));

<Stack.Screen 
  name="Details" 
  component={DetailsScreen}
  options={{ lazy: true }}
/>

Nested Navigation State Access

When navigating within nested navigators, you might need to access the parent navigation:

const { parent } = useNavigation();
parent?.navigate('OtherTab', { screen: 'Details' });

Best Practices for React Native Navigation

  1. Keep navigation logic separate from your UI components. Create dedicated navigation files that define your app’s structure.

  2. Use consistent naming conventions for route names. Consider creating a constants file:

export const SCREENS = {
  HOME: 'Home',
  DETAILS: 'Details',
  PROFILE: 'Profile',
} as const;
  1. Handle hardware back button on Android to provide a natural user experience:
useEffect(() => {
  const unsubscribe = navigation.addListener('gestureEnd', () => {
    navigation.goBack();
  });
  return unsubscribe;
}, [navigation]);
  1. Test navigation flows thoroughly on both platforms, as gesture behaviors can differ between iOS and Android.

Conclusion

Setting up React Native navigation doesn’t have to be overwhelming. By following this guide and using Claude Code’s capabilities, you can implement robust navigation patterns that provide excellent user experiences. Remember to choose the right navigation types for your app’s structure, use TypeScript for type safety, and test thoroughly across platforms. Claude Code can help you extend these patterns further as your app grows in complexity.

Built by theluckystrike — More at zovo.one