Android Jetpack Compose: Navigation
The navigation component in Jetpack Compose helps you navigate between composables and take advantage of the features it provides.
dependencies { def nav_compose_version = "1.0.0-alpha02" implementation "androidx.navigation:navigation-compose:$nav_compose_version" }
NavControllerThe We must create it in the place where composable hierarchy is specified so that all composables that need to reference it can access it. To create a NavController we can use
@Composable fun ToDometerApp() { val navController = rememberNavController() ...
NavHostThe
NavigateTo navigate to a destination, we use
navController.navigate("addProject")
To return to the previous composable we simply call
Passing arguments between destinationsWe can also pass data between destinations by defining placeholders in the composable route, in the same way that we specify path placeholders in a URL.
composable("route/{navArg}")
We can specify the type of argument by passing the
navController.navigate("taskDetail/1")
We can also specify optional arguments by using the following syntax
navController.navigate("taskDetail/?taskId=") // taskId argument = "task1" default value
navController.navigate("taskDetail/?taskId=") // taskId argument = null
Code
Documentationhttps://developer.android.com/jetpack/compose/navigation
Repository
Android News
droidcon News
Tech Showcases, Developer Resources & Partners
EmployerBrandingHeader
jobs.droidcon.com
![]() Latest Android Jobs
Kotlin Weekly
![]() Your weekly dose of Kotlin
ProAndroidDev
![]() Android Tech Blogs, Case Studies and Step-by-Step Coding
Zalando
![]() Meet one of Berlin's top employers
Academy for App Success
![]() Google Play resources tailored for the global droidcon community |
Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.