Status Update
Comments
al...@google.com <al...@google.com>
al...@google.com <al...@google.com> #2
There appears to be guidance on this in the
mv...@google.com <mv...@google.com> #3
That code snippet isn't sufficient as it tells you how to pass data to a new destination when that parameter is always required. Also, it tells you how to do it using a bundle which isn't a valid approach when using the Kotlin DSL.
val bundle = bundleOf("amount" to amount)
which is used in the guide would match a route like the following: "myscreen/{amount}"
.
In this FR, we're talking about optional parameters. So imagine a route like: "myscreen/{amount}?taskId={taskId}"
that could take (or not) that taskId
as parameter. Depending on whether or not taskId
is null, you'd need different routes, either "myscreen/100"
or "myscreen/100?taskId=123123
.To navigate, you'd need to write some code like the following:
fun navigateToMyScreen(amount: String, taskId: String?) {
navController.navigate("myscreen/{amount}").let {
if (taskId != null) "$it?taskId=$taskId" else it
}
}
Description
We should add docs about how to navigate to a destination that contains an optional argument.
We have some places in the Navigation docs where we mention optional parameters ( 1 , 2 ) but we never show how to actually navigate to them.
A best practice to do this might also be nice to show. In the blueprints code , I ended up doing this: