InApps Technology
How to do navigation in React Native web?

How to do navigation in React Native web?

Anh HoangMay 31, 202211 min read

Setting up navigation in react native web is challenging as the navigation system works quite differently in apps vs browser.

“React Native for Web” makes it possible to run React Native components and APIs on the web using React DOM. It is as simple as that!! So, if you have an app and you want to build a web version of it, or if you are planning to build a website along with an app, you should definitely learn React native web.

Setting up navigation in react native web is challenging as the navigation system works quite differently in apps vs browsers.

In this article, we’ll set up the most popular react-navigation on react-native-web.

Key Summary

This article provides a detailed guide on integrating react-navigation into a React Native Web application using Expo, enabling seamless navigation across mobile (iOS/Android) and web platforms. It addresses the challenge of differing navigation systems between apps and browsers, ensuring URL updates reflect screen changes on the web. Key points include:

  • Overview: React Native for Web allows running React Native components on the web via React DOM, ideal for building web versions of apps or simultaneous app/website development. react-navigation is the leading navigation library for React Native, adaptable for web with additional configuration.
  • React Native for Web allows running React Native components on the web via React DOM, ideal for building web versions of apps or simultaneous app/website development.
  • react-navigation is the leading navigation library for React Native, adaptable for web with additional configuration.
  • Prerequisites: Use Expo as the development platform. Install expo-cli and clone the provided GitHub repository (master branch) or use the react-navigation-setup branch for quick setup. Run expo start to initialize the project.
  • Use Expo as the development platform.
  • Install expo-cli and clone the provided GitHub repository (master branch) or use the react-navigation-setup branch for quick setup.
  • Run expo start to initialize the project.
  • Installation:
Install required packages: bash CollapseWrapRun Copy expo install react-navigation react-native-gesture-handler react-native-reanimated react-native-screens
  • npm i react-navigation-stack @react-navigation/web
  • Ensure react-navigation version is 4+ in package.json.
  • Expo ensures compatibility with the installed Expo version, using npm internally.
  • Setup Screens and Navigation: Create Screens: Feed Screen: Displays text and a button to navigate to the Profile screen. Profile Screen: Similar to Feed, with a button to navigate to Feed. Both use StyleSheet for centered layout and Button for navigation via this.props.navigation.navigate. Stack Navigation (Home.js): Use createStackNavigator to connect Feed and Profile screens. Set Profile as the default screen (first in the navigator object). Configure navigationOptions for header styling (e.g., black background, white text). Use createAppContainer to wrap the navigator. App.js: Render the Home navigator within a styled View.
  • Create Screens: Feed Screen: Displays text and a button to navigate to the Profile screen. Profile Screen: Similar to Feed, with a button to navigate to Feed. Both use StyleSheet for centered layout and Button for navigation via this.props.navigation.navigate.
  • Feed Screen: Displays text and a button to navigate to the Profile screen.
  • Profile Screen: Similar to Feed, with a button to navigate to Feed.
  • Both use StyleSheet for centered layout and Button for navigation via this.props.navigation.navigate.
  • Stack Navigation (Home.js): Use createStackNavigator to connect Feed and Profile screens. Set Profile as the default screen (first in the navigator object). Configure navigationOptions for header styling (e.g., black background, white text). Use createAppContainer to wrap the navigator.
  • Use createStackNavigator to connect Feed and Profile screens.
  • Set Profile as the default screen (first in the navigator object).
  • Configure navigationOptions for header styling (e.g., black background, white text).
  • Use createAppContainer to wrap the navigator.
  • App.js: Render the Home navigator within a styled View.
  • Render the Home navigator within a styled View.
  • Running the App: Launch with expo start. Press i for iOS simulator (displays Profile screen; button navigates to Feed). Press w for web browser (same functionality, but URL updates need further configuration).
  • Launch with expo start.
  • Press i for iOS simulator (displays Profile screen; button navigates to Feed).
  • Press w for web browser (same functionality, but URL updates need further configuration).
  • Web-Specific Navigation: Issue: Default setup doesn’t update browser URLs when navigating (e.g., clicking “Go to Feed” doesn’t change URL). Solution: Add static path to screens: Feed: static path = “feed”; Profile: static path = “”; (default route). Direct URL access (e.g., http://localhost:19006/feed) renders the Feed screen.
  • Issue: Default setup doesn’t update browser URLs when navigating (e.g., clicking “Go to Feed” doesn’t change URL).
  • Solution: Add static path to screens: Feed: static path = “feed”; Profile: static path = “”; (default route). Direct URL access (e.g., http://localhost:19006/feed) renders the Feed screen.
  • Add static path to screens: Feed: static path = “feed”; Profile: static path = “”; (default route).
  • Feed: static path = “feed”;
  • Profile: static path = “”; (default route).
  • Direct URL access (e.g., http://localhost:19006/feed) renders the Feed screen.
Replace Button with @react-navigation/web’s Link for web: javascript CollapseWrapRun Copy import { Link } from “@react-navigation/web”;

const isWeb = Platform.OS === ‘web’;

// Conditionally render

  • !isWeb ? <Button … /> : <Link routeName=“Profile”>Go Profile</Link>
Use createBrowserApp instead of createAppContainer for web: javascript CollapseWrapRun Copy const isWeb = Platform.OS === ‘web’;
  • const container = isWeb ? createBrowserApp(Home) : createAppContainer(Home);
  • Result: Clicking navigation buttons updates URLs (e.g., http://localhost:19006/feed), and direct URL entry works.

Using React navigation in react native web

React navigation is the most famous library for navigation in reactnative. In this section, we’ll try to integrate react-navigation in reactnativeweb.

Prerequisite

For this setup, we’ll be using the expo as the platform on which we’ll be building our reactnative app, which will run on android, ios, and the web. Make sure you have expo-cli installed it already.

To set up your codebase using expo, check this GitHub link [master branch]. Simply clone the branch and do run expo start

If you are looking for a quick code, then you can check this GitHub link [NOTE: the branch is reactnavigationsetup and not master.]

Installation

Run the following command to install reactnavigation along with other needed packages including reactnavigationstack.

expo install react-navigation react-native-gesture-handler react-native-reanimated react-native-screens npm i react-navigation-stack npm i @react-navigation/web

Check your package.json files to ensure all of the above packages are installed, make sure reactnavigation is version 4+. If you are wondering, why did we use expo instead of NPM/yarn while installing reactnavigation, then the reason is that expo would look for the correct version of the reactnavigation libraries that’d work with the expo version that’s installed in your project.

If you look into the printed console it uses NPM underneath.

react navigation libraries

Create a few screens

Now, let’s set up a few screens to test our navigation flow:

// feed screen import React from 'react'; import {View, Text, StyleSheet, Button, Platform} from 'react-native'; export default class Feed extends React.Component { render() { return This is the feed screen

Sharein LinkedIn𝕏 X🔗 Copy link

Related Articles

Best Countries to Outsource Software Development (2026 Guide)
Industry Insights

Best Countries to Outsource Software Development (2026 Guide)

Software development outsourcing means hiring an external engineering team - usually based in another country- to design, build, or maintain software on your behalf, instead of hiring in-house. Most US, UK, and Australian companies do this to access skilled engineers faster and at a lower fully-loaded cost than domestic hiring allows.

How to Hire Remote Developers Without Losing Code Quality: A 2026 Playbook for CTOs
Industry Insights

How to Hire Remote Developers Without Losing Code Quality: A 2026 Playbook for CTOs

Every CTO who hires remote developers eventually asks the same question: how do I know this is going to work before I've sunk three months and a sprint's worth of technical debt into finding out? Most guides to hiring remote developers answer a different question: which platform to use. They skip the part that actually determines whether the code that comes back is any good. This playbook covers the vetting mechanics, engagement models, and real rate data behind hiring remote engineers who ship production-quality code from week one, not another list of freelance marketplaces.

IT Managed Services vs Break-Fix IT Support: What Growing Startups Need in 2026
Industry Insights

IT Managed Services vs Break-Fix IT Support: What Growing Startups Need in 2026

Break-fix IT feels free right up until the week something breaks in production and there is no one already watching for it. Here is how growing startups actually decide between break-fix support and managed services in 2026, and why the decision has gotten sharper for anyone shipping a product built quickly with AI tools.