Module 09 Β· Lists & Navigation β Lesson 2 of 4 Β· ~12 min
Navigation Compose: Routes & the Back Stack
The Android way to move between screens
You've seen individual screens β WalkersScreen, WalkerScreen, HomeScreen β but nothing yet about moving between them. Android's standard answer is a library called Navigation Compose. Three pieces:
NavControllerβ an object that remembers which screen is showing and the stack of screens behind it. You get one withval navController = rememberNavController().NavHostβ a composable that owns aNavControllerand a map of routes: string ids β¦ which composable to show.NavHost(navController, startDestination = "walkers") { composable("walkers") { WalkersScreen(...) } }.- Routes β plain strings, like
"walkers"or"walker/{walkerId}". Navigating isnavController.navigate("walker/w1"); going back isnavController.popBackStack()(or the system Back button, which does the same thing automatically).
This is the standard, most-taught way to navigate in a Compose app β and worth knowing well, because you'll meet it in almost every tutorial and most production codebases.