5
AnimatedNavHost(navController, startDestination = BottomNavItem.Splash.screen_route){
composable(
            signup + "/{emailFromSignIn}" + "/{passwordFromSignIn}",
            arguments = listOf(
                navArgument("emailFromSignIn"){
                    type = NavType.StringType
            },navArgument("passwordFromSignIn"){
                    type = NavType.StringType
            }
}
navController.navigate(signup + "/$textEmail" + "/$textPassword")

How can I pass an empty string?

Error:

Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/signup// } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0xb6b16c34) route=splash}

1
  • 1
    Don't forget to test your navigation argument passing for the character $ and / Commented Mar 1, 2022 at 14:06

1 Answer 1

7

You can use an optional parameter with default empty string value:

composable:

composable(
    route = "$signup?emailFromSignIn={emailFromSignIn}&passwordFromSignIn={passwordFromSignIn}",
    arguments = listOf(
        navArgument("emailFromSignIn"){
            type = NavType.StringType
            defaultValue = ""
        },navArgument("passwordFromSignIn"){
            type = NavType.StringType
            defaultValue = ""
        }
    )
) {

navigate:

navController.navigate("$signup?emailFromSignIn=$textEmail&passwordFromSignIn=$textPassword")
Sign up to request clarification or add additional context in comments.

5 Comments

How to build this route before navigate without hardcode?
@AlexS Compose Navigation operates with strings only, you have to build your own system around it to make it less hardcoded. something like this
Thank you. I was looking for information on kotlin dsl navigation, the syntax is too similar.
Optional parameters only work when your url uses format "?arg1=$value1&arg2=$value2" not this format "/arg1=$value1/arg2=$value2"
@AlexS Are you looking this kind of solution? stackoverflow.com/a/77739793/3722222

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.