A Complete Guide to React Native Navigation Using React Navigation

React Native is a popular framework for building mobile applications using JavaScript and React. One of the most important aspects of mobile app development is navigation, which allows users to move seamlessly between different screens and features. React Navigation is a widely used library that simplifies implementing navigation in React Native apps. This guide provides a comprehensive overview of how to use React Navigation effectively.

Getting Started with React Navigation

Before diving into navigation techniques, ensure you have a React Native project set up. Install React Navigation and its dependencies using npm or yarn:

Install core libraries:

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

Don’t forget to install the required peer dependencies and follow the React Navigation documentation for linking and setup instructions.

Basic Navigation Structure

React Navigation uses navigators to manage different types of navigation. The most common are Stack, Tab, and Drawer navigators. Here, we’ll focus on the Stack Navigator, which manages a stack of screens.

First, import the necessary components:

Example:

import { createNativeStackNavigator } from ‘@react-navigation/native-stack’;

Next, create a stack navigator and define your screens:

Example:

const Stack = createNativeStackNavigator();

Then, set up the navigator inside your app component:

Example:

function App() { return ( ); }

Creating Screens

Each screen is a React component. For example:

Home Screen:

function HomeScreen({ navigation }) { return ( Welcome to the Home Screen!