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 with val navController = rememberNavController().
  • NavHost β€” a composable that owns a NavController and 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 is navController.navigate("walker/w1"); going back is navController.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.