expo-router
Expo Router Patterns
Stack Navigator Configuration
Root Layout Setup
Use screenOptions on the Stack component to set defaults for all screens. Do NOT explicitly list every screen - routes are auto-discovered from the file structure.
// app/_layout.tsx
import { Stack } from 'expo-router';
export default function RootLayout() {
return (
<Stack screenOptions={{ headerShown: false }} />
);
}
Per-Screen Configuration
Individual screens configure their own options using <Stack.Screen> within the component file:
// app/lesson/[id].tsx
import { Stack } from 'expo-router';
export default function LessonScreen() {
return (
<View>
<Stack.Screen
options={{
title: 'Lesson',
headerShown: true,
headerBackTitle: 'Back',
}}
/>
{/* Screen content */}
</View>
);
}
Dynamic Header Configuration
Use useNavigation with setOptions for dynamic header content like buttons:
import { useNavigation } from 'expo-router';
import { useLayoutEffect } from 'react';
export default function Screen() {
const navigation = useNavigation();
useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => (
<Pressable onPress={handlePress}>
<Ionicons name="add" size={28} />
</Pressable>
),
});
}, [navigation]);
return <View>{/* content */}</View>;
}
Native Tabs (expo-router/unstable-native-tabs)
Native tabs provide platform-native tab bar with SF Symbols on iOS:
// app/(tabs)/_layout.tsx
import { Icon, Label, NativeTabs } from 'expo-router/unstable-native-tabs';
export default function TabLayout() {
return (
<NativeTabs>
<NativeTabs.Trigger name="index" options={{ title: 'Home' }}>
<Icon sf="house.fill" drawable="custom_android_drawable" />
<Label>Home</Label>
</NativeTabs.Trigger>
</NativeTabs>
);
}
Key Principles
- File-based routing: Routes are auto-discovered from the
app/directory structure - Minimal configuration: Only configure what you need to override
- Screen-level options: Screens configure their own headers/options using
<Stack.Screen>within the component - Layout files:
_layout.tsxfiles define navigation structure for their directory - Route groups: Parentheses like
(tabs)create route groups without affecting the URL path
Common Mistakes to Avoid
- Don't list every screen explicitly in Stack - they're auto-discovered
- Don't use
screenOptionsfor route-specific settings - use<Stack.Screen>in the route file - Don't nest navigators deeply - use file-based routing for cleaner structure
More from jchaselubitz/drill-app
watermelondb
WatermelonDB models, observation patterns, and React integration. Use when writing or debugging model code, observers (findAndObserve, query.observe), or screens that display live-updating DB data.
37expo-audio
Guide for using expo-audio to implement audio playback and recording in React Native apps. Apply when working with audio features, sound playback, recording, or text-to-speech functionality.
17expo-glass-effect
Guide for using expo-glass-effect to create iOS native liquid glass UI effects. Apply when implementing glass effect UI components, cards, or surfaces on iOS.
9zod-v4-patterns
Ensures Zod v4 patterns are used correctly throughout the codebase. Apply when creating or modifying validation schemas, form schemas, or any Zod validators. Enforces v4 syntax and prevents deprecated v3 patterns.
5rn-button-component
Ensures buttons use the unified Button component with proper state management, icon support, and glass effect integration. Apply when creating or modifying buttons in the app.
5gemini-api
Patterns for using Google Gemini API with structured output, JSON mode, and proper configuration. Apply when implementing AI features, text generation, or working with Gemini models.
4