Jetpack compose navigation with multiple optional argments

Viewed 2912

https://developer.android.com/jetpack/compose/navigation#optional-args

been going through documentation to figure out how to use multiple optional arguments and how to pass them

but in docs only one param is mentioned.

composable(
    "profile?userId={userId}",
    arguments = listOf(navArgument("userId") { defaultValue = "me" })
) 

and call it with

composable("profile")
composable("profile/user123") // if you want to pass param

how to declare and call for two params ?

1 Answers

how to declare ?

  composable(
    "profile?userId={userId}&userType={userType}",
    arguments = listOf(
      navArgument("userType") {
        defaultValue = "ADMIN"
        type = NavType.StringType
      }, navArgument("userId") {
        nullable = true
        defaultValue = null
        type = NavType.StringType
      })
  ) 

how to call ?

navController.navigate("profile?userId=user123&userType=user")
navController.navigate("profile?userType=user")
navController.navigate("profile")
Related