Pages Navigation
Pages navigation is for managing a list of pages, where one selected page that is shown to the user.
Define your navigation model, (as already covered in model-driven navigation section)
@Serializable
enum class PagesScreens { Page1, Page2, Page3 }
Creating a router with page navigation model
@Composable
fun PagesScreen() {
val router: Router<PagesScreens> = rememberRouter { pagesOf(Page1, Page2, Page3) }
}
Consuming the state from the router
Use RoutedContent
to consume the state from the router.
@Composable
fun PagesScreen() {
val router: Router<PagesScreens> = rememberRouter { pagesOf(Page1, Page2, Page3) }
RoutedContent(router = router) { screen: PagesScreens ->
when (screen) {
Page1 -> Page1Screen()
Page2 -> Page2Screen()
Page3 -> Page3Screen()
}
}
}
Navigating with page navigation router
Decompose-router exposes the same Decompose page navigator extension functions
val router: Router<PagesScreens> = rememberRouter { pagesOf(Page1, Page2, Page3) }
// To go to second page
Button(onClick = { number -> router.select(1) })
// To go back to first screen
Button(onClick = { router.selectFirst() })
Last modified: 04 December 2024