navigation<ShopGraph>(startDestination = Catalog) { ... } groups the catalog and the detail screen into a nested graph, a destination that contains destinations. Navigating to ShopGraph lands on its start destination, a whole flow can be popped at once, and the bottom bar can treat "anywhere in the shop" as one tab. Top-level tabs use Material 3 15,533 's NavigationBar:
val selected = entry?.destination?.hierarchy
?.any { it.hasRoute(item.route::class) } == true
NavigationBarItem(
selected = selected,
onClick = {
nav.navigate(item.route) {
popUpTo(nav.graph.findStartDestination().id) { saveState = true }
launchSingleTop = true // no second copy on reselect
restoreState = true // come back to the saved stack
}
},The three options are the standard recipe. popUpTo with saveState clears everything above the start destination but saves it, so switching tabs never piles screens up; restoreState brings a tab's saved stack back; launchSingleTop stops a second copy of the tab. hierarchy walks up from the current destination through its parent graphs, so the Books tab stays selected on a detail screen. With Salt and Saffron open, tapping Books, pressing Back, opening The Quiet Harbor, then Cart, Books and Cart again logged:
D/BookNestNav: now at com.example.booknest.ui.nav.BookDetail/{id} id=3
D/BookNestNav: now at com.example.booknest.ui.nav.Catalog
D/BookNestNav: now at com.example.booknest.ui.nav.BookDetail/{id} id=1
D/BookNestNav: now at com.example.booknest.ui.nav.Cart
D/BookNestNav: now at com.example.booknest.ui.nav.BookDetail/{id} id=1
D/BookNestNav: now at com.example.booknest.ui.nav.CartTapping Books from Cart restored the shop tab exactly where it was, on book 1, and tapping Books while already inside it restored the same detail rather than jumping to the catalog.