codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
⚛️

React.js

55 / 61 topics
52Introduction to React Native53Building Your First App with React Native54State Management in React Native55Navigation in React Native56Performance Tips for React Native Apps
Tutorials/React.js/Navigation in React Native
⚛️React.js

Navigation in React Native

Updated 2026-04-20
3 min read

Introduction

Navigation is a crucial aspect of any mobile application, allowing users to move between different screens or components within your app. In React Native, the react-navigation library provides a powerful and flexible way to handle navigation across various platforms. This tutorial will guide you through setting up and using navigation in a React Native application.

Setting Up React Navigation

Before diving into navigation, ensure that you have a React Native project set up. If not, you can create one using the following command:

npx react-native init MyNavigationApp

Navigate to your project directory:

cd MyNavigationApp

Installing React Navigation Packages

React Navigation is composed of several packages that work together to provide different types of navigation. For this tutorial, we'll use @react-navigation/native for core functionalities and @react-navigation/stack for stack-based navigation.

Install the necessary packages:

npm install @react-navigation/native @react-navigation/stack

Additionally, you need to install some dependencies that are required by React Navigation:

npm install react-native-screens react-native-safe-area-context

Linking Native Dependencies

For React Native projects using Expo, the linking step is handled automatically. However, for bare React Native projects, you need to link the native dependencies manually. Run the following command:

npx pod-install ios

Basic Stack Navigation Setup

Stack navigation is one of the most common types of navigation where each screen has a back button that navigates to the previous screen.

Creating a Stack Navigator

First, import the necessary components from @react-navigation/stack and set up your stack navigator in your main application file (usually App.js).

import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

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

const HomeScreen = ({ navigation }) => {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Home Screen</Text>
      <Button
        title="Go to Details"
        onPress={() => navigation.navigate('Details')}
      />
    </View>
  );
};

const DetailsScreen = () => {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Details Screen</Text>
    </View>
  );
};

export default App;

Explanation

  • NavigationContainer: This is the root component that manages the navigation tree and contains the navigation state.
  • Stack.Navigator: Defines a stack of screens where each screen has a back button to navigate back to the previous screen.
  • Stack.Screen: Represents a single screen in the stack. The name prop is used to identify the screen, and the component prop specifies the component to render for that screen.

Navigating Between Screens

In the HomeScreen component, we use the navigation prop provided by React Navigation to navigate to the DetailsScreen. This prop has a navigate method that takes the name of the target screen as an argument.

Customizing Stack Navigator

React Navigation allows you to customize various aspects of your stack navigator, such as screen options and transition animations.

Screen Options

You can set default options for all screens in the stack or override them for specific screens.

<Stack.Navigator initialRouteName="Home" screenOptions={{
  headerStyle: {
    backgroundColor: '#f4511e',
  },
  headerTintColor: '#fff',
  headerTitleStyle: {
    fontWeight: 'bold',
  },
}}>
  <Stack.Screen name="Home" component={HomeScreen} />
  <Stack.Screen name="Details" component={DetailsScreen} options={{
    title: 'My Details',
  }} />
</Stack.Navigator>

Transition Animations

React Navigation provides several built-in transition animations that you can use to enhance the user experience.

<Stack.Navigator initialRouteName="Home" screenOptions={{
  gestureEnabled: true,
  cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
}}>
  <Stack.Screen name="Home" component={HomeScreen} />
  <Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>

Handling Parameters

You can pass parameters between screens using the navigation.navigate method.

<Button
  title="Go to Details with Param"
  onPress={() => navigation.navigate('Details', { itemId: 86 })}
/>

In the DetailsScreen, you can access these parameters via the route prop:

const DetailsScreen = ({ route }) => {
  const { itemId } = route.params;
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Item ID: {itemId}</Text>
    </View>
  );
};

Best Practices

  • Use Descriptive Screen Names: This makes your code more readable and maintainable.
  • Avoid Deeply Nested Navigators: While possible, deeply nested navigators can lead to performance issues. Consider using tabs or drawers for complex navigation structures.
  • Customize Navigation Options Consistently: Ensure that all screens have consistent header styles and animations for a cohesive user experience.

Conclusion

React Native's react-navigation library provides a robust solution for handling navigation in cross-platform mobile applications. By following this tutorial, you should be able to set up basic stack navigation, customize it according to your needs, and pass parameters between screens. As you become more familiar with React Navigation, explore other types of navigators like tabs and drawers to build more complex and feature-rich applications.

Additional Resources

  • React Navigation Official Documentation
  • React Native Expo
  • React Native CLI

PreviousState Management in React NativeNext Performance Tips for React Native Apps

Recommended Gear

State Management in React NativePerformance Tips for React Native Apps