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 yourapp directory becomes a route. The file name determines the URL path.
Route Conventions
Index Routes
Files namedindex 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
/profile/123→{ id: '123' }/profile/john→{ id: 'john' }
Multiple Dynamic Segments
You can have multiple dynamic segments:app/posts/[category]/[id].tsx
/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
/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:
Route Groups
Parentheses(group) create organization without affecting the URL:
- Organize files logically
- Apply different layouts to different sections
- Keep routes at the same URL level
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
Route Resolution
Expo Router uses specificity scoring to resolve routes:Specificity Order (highest to lowest)
- Exact matches:
about.tsx>[slug].tsxfor/about - Dynamic routes:
post/[id].tsx>[...all].tsxfor/post/123 - Catch-all routes:
[...all].tsxmatches everything else
Example
/blog→blog/index.tsx/blog/post-1→blog/[slug].tsxwith{ slug: 'post-1' }/blog/2024/january→blog/[...all].tsxwith{ all: ['2024', 'january'] }
Platform-Specific Routes
Create platform-specific routes with file extensions:- Platform-specific file (
.ios.tsx,.android.tsx,.web.tsx) - Native file (
.native.tsx) for iOS/Android - Default file (
.tsx)
Array Syntax
Multiple route groups can share files using comma syntax:getRoutesCore.ts:74):
Route Processing Pipeline
Under the hood, Expo Router converts files to routes:- File Discovery: Metro’s
require.context()finds all route files - Route Tree: Files are converted to a
RouteNodetree structure - Specificity Scoring: Routes get specificity scores for matching
- Navigation Config: React Navigation configuration is generated
- Deep Linking: URL patterns are created automatically
CLAUDE.md:77-83:
Best Practices
File Organization
Naming Conventions
- Use lowercase for file names:
profile.tsx, notProfile.tsx - Use hyphens for multi-word names:
user-settings.tsx - Use clear, descriptive names:
invoice-details.tsx, notid.tsx
Dynamic Route Naming
- Be specific:
[userId].tsxis 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