https://kotlinlang.org logo
#compose
Title
# compose
b

Billy Newman

06/10/2022, 8:50 PM
Hello all, seeing what I think might be a bug w/ compose navigation using a startDestination with a nullable default parameter. If my NavHost is using a route with a nullable default parameter it seems the navigation lib cannot find the route.
Copy code
navigation destination home?foo=bar is not a direct child of this NavGraph
Code in reply
Copy code
NavHost(
            navController = navController,
            startDestination = "home"
         ) {
            composable(
              route = "home?foo={bar}",
              arguments = listOf(navArgument("foo") { defaultValue = ""; })
            ) { backstackEntry ->
versions:
Copy code
navigation-compose:2.4.2
compose-version:1.2.0-beta03
I have tried different combinations of nav argument with defaultValue, and nullable. Also tried to pass a dummy arg in the startDestination route. Is this a bug or am I doing something wrong?
Should note, searched through issue tracker, didn’t find anything.
b

Billy Newman

06/10/2022, 9:11 PM
Ah, arguments is the issue. Thank you!
Ian, any idea if this has been discussed as a future enhancement. Things start to get messy quickly when using string constants for route values. Sure you can add “{userId}” to the route constant. However you still run into issues when trying to navigate to a route with a non default parameter if using the sting constant. In the case of using arguments, perhaps the startDestination could match on the everything but the args. I am sure there is a lot more at play, just a thought
i

Ian Lake

06/10/2022, 9:57 PM
If this is anything to do with your previous thread and how you are trying to build dynamic destinations, then you're just misusing arguments entirely 🙂
The start destination of your graph should just be
home
because your route for your screen should be
home
- arguments shouldn't be a part of it at all
👍 2
I commented back on your other thread with what I was suggesting
b

Billy Newman

06/10/2022, 10:49 PM
Ugh, sorry Ian, that makes sense. Home will not be my app entry point, it is temporarily as I build out the app.
12 Views