What would be the best practice for defining multi...
# compose
a
What would be the best practice for defining multiple required arguments for compose navigation? Let’s say there’s multiple ids I need to pass. How about something like this?
screenA/itemId/userId/someToken
Or is below better even though the syntax is for optional arguments…
screenA/itemId?userId={userId}&someToken={someToken}
i
The guide is pretty clear that you should put arguments in the path of the route if they are required and in query parameters if they are optional
1
👍 1
a
Yeah, it’s just that I got feedback that it looks weird…
i
TBH, a
userId
and a
someToken
sound like things that should be injected in and controlled centrally, not something you'd pass as arguments at all
p
@allan.conda instead of hardcoding the query I extract extension function:
Copy code
private fun String.withParams(vararg params: String): String =
    "$this?" + params.joinToString("&") { param -> "$param={$param}" }
and I call:
Destinations.ScreenA.withParams(Param.A, Param.B)
to declare the route.