--- name: expo-router user-invocable: false description: Use when implementing file-based routing in Expo with Expo Router. Covers app directory structure, navigation, layouts, dynamic routes, and deep linking. allowed-tools: - Read - Write - Edit - Bash - Grep - Glob --- # Expo Router Use this skill when implementing file-based routing with Expo Router, the recommended navigation solution for Expo apps. ## Key Concepts ### File-Based Routing Routes are defined by file structure: ``` app/ _layout.tsx # Root layout index.tsx # / route about.tsx # /about route (tabs)/ # Group (not in URL) _layout.tsx # Tabs layout home.tsx # /home profile.tsx # /profile users/ [id].tsx # /users/:id dynamic route index.tsx # /users route ``` ### Basic Routes ```tsx // app/index.tsx import { View, Text } from 'react-native'; import { Link } from 'expo-router'; export default function Home() { return ( Home Screen Go to About ); } // app/about.tsx export default function About() { return ( About Screen ); } ``` ### Layouts ```tsx // app/_layout.tsx import { Stack } from 'expo-router'; export default function RootLayout() { return ( ); } ``` ### Tab Navigation ```tsx // app/(tabs)/_layout.tsx import { Tabs } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; export default function TabLayout() { return ( ( ), }} /> ( ), }} /> ); } ``` ## Best Practices ### Dynamic Routes ```tsx // app/users/[id].tsx import { useLocalSearchParams } from 'expo-router'; import { View, Text } from 'react-native'; export default function UserDetails() { const { id } = useLocalSearchParams<{ id: string }>(); return ( User ID: {id} ); } // Navigate to /users/123 View User // Or import { router } from 'expo-router'; router.push('/users/123'); ``` ### Programmatic Navigation ```tsx import { router } from 'expo-router'; function MyComponent() { const handlePress = () => { // Navigate to route router.push('/details'); // Navigate with params router.push({ pathname: '/users/[id]', params: { id: '123' }, }); // Replace current route router.replace('/login'); // Go back router.back(); }; return