Skip to content
codmaker

Expo Router: File-Based Navigation for React Native

How Expo Router works: file-based routes, layouts, dynamic segments, typed routes and universal links, plus when to pick it over React Navigation.

CodmakerUpdated 8 min read
Share

What Is Expo Router?

Expo Router is a file-based router for React Native and the web. You create a file inside the app directory, and that file becomes a screen. The folder structure is the navigation structure. No route config objects, no manual screen registration.

If you know Next.js, you already know Expo Router. The mental model is the same: files map to URLs, folders map to nested routes, and layout files wrap the screens below them. That is the whole point. One routing model for your mobile app and your web app.

Under the hood, Expo Router is built on top of React Navigation. You still get native stacks, tabs and drawers with real native transitions. Expo Router just replaces the imperative setup with files and URLs, and it gives every screen a path you can link to.

Why Use File-Based Routing in React Native?

Navigating by creating files in an app directory feels far more natural than the imperative boilerplate of classic react-navigation setups. You stop wiring navigators by hand and stop keeping a separate list of screen names in sync with your components.

The bigger win is that every screen has a URL. That one decision fixes a lot of problems at once. Deep linking is solved out of the box. Sharing a screen is sharing a path. Web support comes almost for free, because a URL is already how the web works.

It also makes codebases easier to read. A new developer opens the app folder and sees the product map. They do not have to trace navigator definitions across five files to find where a screen lives.

  • Screens are files, so the folder tree documents your navigation
  • Every screen gets a URL, which gives you deep links by default
  • The same routes can render on iOS, Android and the web
  • Layouts keep shared UI like headers and tab bars in one place

How Expo Router Works: Routes, Layouts and Dynamic Segments

A file named index.tsx inside app is your home route. A file at app/settings.tsx becomes /settings. Nest folders to nest paths: app/user/profile.tsx is /user/profile.

Layout files are named _layout.tsx. A layout wraps every route in its folder and decides how they are presented. Export a Stack from expo-router to get a native stack, or Tabs to get a tab bar. The root layout at app/_layout.tsx is also where you put providers like your theme, auth or data-fetching client.

Dynamic segments use square brackets. A file at app/user/[id].tsx matches /user/42 or /user/mustapha. Inside the screen, read the value with the useLocalSearchParams hook. Catch-all routes use the spread form, like [...rest].tsx.

Folders wrapped in parentheses are groups. A folder like (tabs) or (auth) organizes files and lets you attach a layout without adding a segment to the URL. This is how you put a tab navigator around a set of screens while keeping clean paths.

To move between screens, use the Link component with an href, or call router.push and router.replace from the useRouter hook when you need to navigate from code, for example after a form submits.

How to Use Typed Routes in Expo Router

Typed routes are one of the best parts of Expo Router. The router can statically analyze your app directory and generate TypeScript types for every route. The result: you can't navigate to a screen that doesn't exist. A typo in an href becomes a compile error.

That catches broken links at build time, not at runtime in front of a user. On a growing app, where screens get renamed and moved, this is the difference between a confident refactor and a week of hunting dead links.

Typed routes are switched on through your app config, and the exact setting has changed across Expo SDK releases. Check the Expo Router docs for the SDK you are on instead of copying an old snippet. Once it is on, the types are regenerated as you add or rename files while the dev server runs.

Expo Router vs React Navigation: When to Use Each

This is not really a versus. Expo Router uses React Navigation under the hood. The question is whether you want to configure navigation by hand or let the file system do it.

Pick Expo Router for new Expo projects, apps that also ship a web version, and products where links and sharing matter. It is the default in new Expo templates for a reason.

Stick with plain React Navigation if you have a large existing app with complex custom navigators and no appetite for a migration, or if you are on a bare React Native setup where adopting Expo tooling is not on the table. Migrating is doable, but it touches every screen, so plan it as a real project.

Common Expo Router Mistakes

Most issues come from treating Expo Router like the old imperative setup. A few patterns show up again and again.

  • Putting non-route files like components or utils inside the app folder, where they get treated as routes. Keep them outside app.
  • Forgetting that a layout wraps everything in its folder, then wondering why a header shows up on the wrong screen
  • Using groups and dynamic segments in a way that makes two files resolve to the same URL
  • Assuming universal links work after setting a scheme. You still need the domain verification files.
  • Copying typed routes or config snippets from an older SDK without checking the current docs

Frequently Asked Questions

Is Expo Router the same as Next.js routing?

Not the same code, but the same idea. Both use file-based routing where files in an app directory map to URLs and layout files wrap nested routes. If you have built with the Next.js App Router, Expo Router will feel familiar right away.

Does Expo Router replace React Navigation?

No. Expo Router is built on top of React Navigation. It replaces the manual navigator configuration with file-based routes, but the stacks, tabs and transitions underneath are still React Navigation.

Can I use Expo Router without Expo?

Expo Router is designed around the Expo toolchain, including its bundler config and CLI. You can add Expo packages to an existing React Native app, but if you want Expo Router, the smoothest path is a project set up with Expo.

How do I pass parameters between screens in Expo Router?

Put them in the URL. Use a dynamic segment like [id].tsx for required values, or query parameters for optional ones, then read them in the target screen with useLocalSearchParams. Keep params small and serializable, and fetch the full data on the screen.

Does Expo Router support the web?

Yes. The same routes render on the web, and every screen gets a real URL. That is a big part of why universal links and shareable content work so well with it.

Written by Codmaker

An independent product lab. We build and run our own React Native and Next.js apps, and write up what we learn along the way.

See our apps
All guides →