Architecture · 8 min read · Intermediate
Screen Navigation with Navigation Compose
Wire multi-screen flows with type-safe routes, back-stack handling, and deep links.
What you'll learn
- Define clear routes inside `NavHost`
- Handle back-stack pops cleanly with `popUpTo` and `launchSingleTop`
- Keep screen composables decoupled from `NavController`
Overview
Wire multi-screen flows with type-safe routes, back-stack handling, and deep links.
Code Example
NavHost(navController = navController, startDestination = "home") {
composable("home") { HomeScreen(onOpen = { slug -> navController.navigate("course/$slug") }) }
composable("course/{slug}") { backStack ->
val slug = backStack.arguments?.getString("slug").orEmpty()
CourseScreen(slug = slug)
}
}
Key Takeaways
- Define clear routes inside
NavHost - Handle back-stack pops cleanly with
popUpToandlaunchSingleTop - Keep screen composables decoupled from
NavController
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why is passing navigation callback lambdas (`onBack: () -> Unit`) better than passing `NavController` into every screen?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.