File-Based Routing
DPM Delivery Mobile uses Expo Router for navigation, which provides a file-based routing system. Routes are automatically generated based on the file structure in thesrc/app/ directory.
Route Structure
Root Layout
The root layout sets up global providers and defines top-level navigation:Key Features:
- unstable_settings: Defines initial route and anchor
- Providers: Wraps entire app with necessary providers (TanStack Query, Gesture Handler, etc.)
- Stack: Root stack navigator with two main route groups
Route Groups
Route groups use parentheses() to organize routes without affecting the URL structure.
(public) Route Group
Handles unauthenticated routes like sign-in:/(public)/(auth)/sign-in- Sign in page
(parcel) Route Group
Handles authenticated routes with auth guard:- Check if user exists in storage
- Redirect to sign-in if not authenticated
- Render child routes if authenticated
Tab Navigation
The(tabs) group creates a bottom tab navigator:
- Haptic feedback on tab press
- SF Symbols icons (iOS) with fallback
- Theme-aware colors
- Four main tabs: Home, History, Transactions, Profile
Stack Navigation
The(stack) group creates a stack navigator for modal-like screens:
- Custom back button with fallback to tabs
- Header configuration per screen
- Safe navigation handling
Dynamic Routes
Dynamic segments use square brackets[]:
/shipments/:reference
Example URLs:
/shipments/SHP-12345/shipments/ORD-67890
Navigation Patterns
Programmatic Navigation
Link Component
Conditional Redirects
Type-Safe Routes
Expo Router provides TypeScript autocomplete for routes. Configure intsconfig.json:
Navigation Best Practices
- Use route groups for organizing related screens without affecting URLs
- Implement auth guards at layout level for protected routes
- Handle back navigation safely with
canGoBack()checks - Use typed parameters with
useLocalSearchParams<T>() - Prefer
replace()for auth flows to prevent back navigation - Use descriptive names for dynamic segments:
[reference],[id], etc.