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

Peter Mandeljc

01/19/2023, 2:36 PM
Does anyone know, why following navigation is giving me
java.lang.IllegalArgumentException: navigation destination files is not a direct child of this NavGraph
exception? If I remove optional arguments, it works ok.
Copy code
NavHost(
    navController = controller,
    startDestination = "files"
) {
    composable(
        route = "files?import_file={import_file}",
        arguments = listOf(navArgument("import_file") { defaultValue = false })
    ) { backStack ->
        FilesScreen(
            openImportDrawer = backStack.arguments?.getBoolean("import_file") ?: false,
        )
    }
}
i

Ian Lake

01/19/2023, 4:45 PM
The route strings (the
startDestination
and the
route
) need to match character by character, so you need to use
startDestination = "files?import_file={import_file}"
p

Peter Mandeljc

01/19/2023, 5:05 PM
I see, thanks. I thought it would work, since route argument is optional. Would it make sense to suggest this use case as a feature request?
i

Ian Lake

01/19/2023, 5:10 PM
No, the
startDestination
is a route pattern, it isn't how you pass arguments (e.g.,
startDestination = "files?import_file=true"
is also not expected to work - to do that, you'd set the
defaultValue
). There's no plans on changing that
268 Views