SKILL.md--- name: rn-navigation description: Expo Router navigation patterns for React Native. Use when implementing navigation, routing, deep links, tab bars, modals, or handling navigation state in Expo apps. --- # React Native Navigation (Expo Router) ## File-Based Routing Fundamentals Expo Router uses file-system based routing. Files in `app/` become routes. ### Route Structure ``` app/ ├── _layout.tsx # Root layout (providers, global UI) ├── index.tsx # "/" route ├── (tabs)/ # Tab group (parentheses = layout group) │ ├── _layout.tsx # Tab bar configuration │ ├── home.tsx # "/home" tab │ └── profile.tsx # "/profile" tab ├── (auth)/ # Auth flow group │ ├── _layout.tsx # Auth-specific layout │ ├── login.tsx # "/login" │ └── register.tsx # "/register" ├── settings/ │ ├── index.tsx # "/settings" │ └── [id].tsx # "/settings/123" (dynamic) └── [...missing].tsx # Catch-all 404 ``` ### Layout Groups `(groupName)` Parentheses create layout groups - they affect layout hierarchy but not URL: ```typescript // app/(tabs)/_layout.tsx import { Tabs } from 'expo-router'; export default function TabLayout() { return ( <Tabs> <Tabs.Screen name="home" options={{ title: 'Home', tabBarIcon: ({ color }) => <HomeIcon color={color} />, }} /> <Tabs.Screen name="profile" options={{ title: 'Profile' }} /> </Tabs> ); } ``` ### Dynamic Routes `[param]` ```typescript // app/player/[id].tsx import { useLocalSearchParams } from 'expo-router'; export default function PlayerScreen() { const { id } = useLocalSearchParams<{ id: string }>(); return <PlayerProfile playerId={id} />; } ``` ### Catch-All Routes `[...slug]` ```typescript // app/[...missing].tsx import { Link, Stack } from 'expo-router'; export default function NotFound() { return ( <> <Stack.Screen options={{ title: 'Not Found' }} /> <Link href="/">Go home</Link> </> ); } ``` ## Navigation Patterns ### Programmatic Navigation ```typescript import { useRouter, Link } from 'expo-router'; function MyComponent() { const router = useRouter(); // Navigate with push (adds to stack) router.push('/player/123'); // Navigate with params router.push({ pathname: '/player/[id]', params: { id: '123' }, }); // Replace current screen (no back) router.replace('/home'); // Go back router.back(); // Navigate to root router.navigate('/'); // Dismiss modal router.dismiss(); } ``` ### Link Component ```tsx import { Link } from 'expo-router'; // Simple link <Link href="/settings">Settings</Link> // With params <Link href={{ pathname: '/player/[id]', params: { id: '123' } }}> View Player </Link> // As button <Link href="/schedule" asChild> <Pressable> <Text>View Schedule</Text> </Pressable> </Link> // Replace instead of push <Link href="/home" replace>Home</Link> ``` ## Stack Navigation ```typescript // app/_layout.tsx import { Stack } from 'expo-router'; export default function RootLayout() { return ( <Stack> <Stack.Screen name="(tabs)" options={{ he