import{ useRouter }from'expo-router';functionMyComponent(){const router =useRouter();// Navegar a una ruta router.push('/explore');// Con parámetros router.push({ pathname:'/item-detail', params:{ id:'123'}});// Reemplazar (sin poder volver) router.replace('/home');// Go back router.back();// Ir a tab específico router.push('/(tabs)/favorites');}
Parámetros de Ruta
// En la pantalla de detalleimport{ useLocalSearchParams }from'expo-router';functionDetailScreen(){const{ id, title }=useLocalSearchParams<{ id:string; title?:string;}>();return<Text>Item ID:{id}</Text>;}
Link Component
import{ Link }from'expo-router';<Link href="/explore" asChild><TouchableOpacity><Text>Ir a Explorar</Text></TouchableOpacity></Link>// Con parámetros<Link
href={{ pathname:'/item-detail', params:{ id:'123'}}} asChild
><Button title="Ver detalle"/></Link>
// Dentro del componente de la pantallaimport{ Stack }from'expo-router';functionProductScreen(){const{ name }=useProduct();return(<><Stack.Screen
options={{ title: name,headerRight:()=><ShareButton />,}}/>{/* Contenido */}</>);}
Patrones Comunes
Deep Linking
// Navegar a pantalla anidadarouter.push('/(tabs)/profile/edit-profile');// Desde notificación pushconsthandleNotification=(notification)=>{const{ screen, params }= notification.data; router.push({ pathname: screen, params });};