Navigation Across Modules
Connect features without coupling.
The Navigation Challenge
Once features live in separate modules, a new question appears: how does :feature:home open a screen in :feature:profile without depending on it? If features import each other directly, you get coupling and risk cycles.
In this lesson you will connect features through navigation while keeping them independent.
Where the NavHost Lives
The single NavHost lives in the :app module, the one place that is allowed to know about every feature. Each feature contributes its destinations, and :app assembles them into one graph.
// app/AppNavHost.kt
@Composable
fun AppNavHost(navController: NavHostController = rememberNavController()) {
NavHost(navController, startDestination = HomeRoute) {
homeScreen(onProfileClick = { navController.navigate(ProfileRoute) })
profileScreen(onBack = { navController.popBackStack() })
}
}All lessons in this course
- Why Modularize
- Feature and Core Modules
- Managing Module Dependencies
- Navigation Across Modules