React Navigation is the de facto routing library for React Native, offering several navigator types. Stack.Navigator manages a stack of screens where users push and pop views, ideal for hierarchical flows like a list leading to a detail page. Tab.Navigator displays a persistent bar at the bottom (or top) for switching between peer-level screens, suitable for 3-5 top-level destinations. Drawer Navigator presents a side menu that slides in from the edge or via a hamburger icon, useful for apps with many destinations. The createNativeStackNavigator function uses UINavigationController on iOS and Fragment on Android, providing native-looking transitions and better performance compared to the JavaScript-based createStackNavigator from @react-navigation/stack.
Programmatic navigation is performed through the navigation prop, accessed directly in components or via the useNavigation hook. Methods include navigate, push, goBack, replace, and reset, allowing fine-grained control over the stack state. To pass typed parameters between screens in TypeScript, declare a RootStackParamList mapping route names to their param shapes and pass it as a type argument to the navigator. By default, screens in a navigation stack remain mounted, so component state persists when navigating away and back. The useFocusEffect hook runs an effect when a screen gains focus and cleans up when it loses focus, mirroring useEffect but tied to the navigation lifecycle rather than mount lifecycle, which is essential for refetching data when a user returns to a screen.
Deep linking connects URLs to specific screens. In React Navigation, configure the linking prop on NavigationContainer with prefixes and a config object mapping URL paths to screens, for example mapping screens to user/:id. On the native side, configure URL schemes in Info.plist for iOS and AndroidManifest for Android, and for universal links, host an apple-app-site-association file on your domain. The Linking module complements this by letting the app open outgoing URLs in other apps via Linking.openURL and verify scheme support with Linking.canOpenURL. expo-router offers an alternative file-based routing approach where the file structure inside an app/ directory automatically becomes the navigation tree, similar to Next.js but for native apps.