Does anyone know, why following navigation is givi...
# compose
p
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
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
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
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
473 Views