Skip to main content

File-Based Routing

Expo Router uses your file system structure to automatically generate navigation routes. This guide covers all the routing conventions and how files map to URLs.

Basic Concepts

Every file in your app directory becomes a route. The file name determines the URL path.

Route Conventions

Index Routes

Files named index match the root of the directory:
app/index.tsx

Named Routes

Any other filename creates a route with that name:

Nested Routes

Directories create nested URL paths:

Dynamic Routes

Use square brackets [param] to create dynamic route segments:

Single Dynamic Segment

app/profile/[id].tsx
Matches:
  • /profile/123{ id: '123' }
  • /profile/john{ id: 'john' }

Multiple Dynamic Segments

You can have multiple dynamic segments:
app/posts/[category]/[id].tsx
Matches:
  • /posts/tech/123{ category: 'tech', id: '123' }
  • /posts/sports/456{ category: 'sports', id: '456' }

Catch-All Routes

Use [...segments] to match multiple path segments:
app/docs/[...slug].tsx
Matches:
  • /docs/intro{ slug: ['intro'] }
  • /docs/guide/getting-started{ slug: ['guide', 'getting-started'] }
  • /docs/api/v1/users{ slug: ['api', 'v1', 'users'] }

Layout Routes

Files named _layout create shared layouts:
Layouts wrap their child routes. See the Layouts guide for details.

Route Groups

Parentheses (group) create organization without affecting the URL:
Route groups are invisible in URLs but allow you to:
  • Organize files logically
  • Apply different layouts to different sections
  • Keep routes at the same URL level
See the Route Groups guide for details.

Special Files

Not Found Route

+not-found.tsx handles 404 errors:
app/+not-found.tsx

API Routes

+api.ts files create API endpoints:
app/users/[id]+api.ts
See the API Routes guide for details.

Route Resolution

Expo Router uses specificity scoring to resolve routes:

Specificity Order (highest to lowest)

  1. Exact matches: about.tsx > [slug].tsx for /about
  2. Dynamic routes: post/[id].tsx > [...all].tsx for /post/123
  3. Catch-all routes: [...all].tsx matches everything else

Example

Route matching:
  • /blogblog/index.tsx
  • /blog/post-1blog/[slug].tsx with { slug: 'post-1' }
  • /blog/2024/januaryblog/[...all].tsx with { all: ['2024', 'january'] }

Platform-Specific Routes

Create platform-specific routes with file extensions:
Resolution order:
  1. Platform-specific file (.ios.tsx, .android.tsx, .web.tsx)
  2. Native file (.native.tsx) for iOS/Android
  3. Default file (.tsx)

Array Syntax

Multiple route groups can share files using comma syntax:
This is equivalent to:
From the source code (getRoutesCore.ts:74):

Route Processing Pipeline

Under the hood, Expo Router converts files to routes:
  1. File Discovery: Metro’s require.context() finds all route files
  2. Route Tree: Files are converted to a RouteNode tree structure
  3. Specificity Scoring: Routes get specificity scores for matching
  4. Navigation Config: React Navigation configuration is generated
  5. Deep Linking: URL patterns are created automatically
From CLAUDE.md:77-83:

Best Practices

File Organization

Naming Conventions

  • Use lowercase for file names: profile.tsx, not Profile.tsx
  • Use hyphens for multi-word names: user-settings.tsx
  • Use clear, descriptive names: invoice-details.tsx, not id.tsx

Dynamic Route Naming

  • Be specific: [userId].tsx is better than [id].tsx
  • Use camelCase in brackets: [postId].tsx, [categorySlug].tsx

Common Patterns

Auth Flow

Tabbed Interface

Nested Navigation

E-commerce

Next Steps

Navigation

Learn how to navigate between routes

Dynamic Routes

Master dynamic route parameters

Layouts

Create shared layouts for your routes

Route Groups

Organize routes without affecting URLs