I have created a destination for HistoryDetail
screen in my app.
composable(
route = "HistoryDetail/{webpage}",
arguments = listOf(
navArgument("webpage") {
type = NavType.StringType
}
),
) { entry ->
val text = entry.arguments?.getString("webpage") ?: ""
}
When I try to navigate to that screen by calling:
navController.navigate("HistoryDetail/http://alphaone.me/")
I'm getting illegalArgumentException
with the below message.
java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/HistoryDetail/http://alphaone.me/ } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x78c9ba0c) route=Home}
Edit:
It works if I call: navController.navigate("HistoryDetail/test")
.
The way it is currently done in jetpack compose is by appending the route with arguments and their respective values. For example, let’s say that we have a composable with route = “userPage”, and we want to pass arguments “userId” and “isLoggedIn”. The following snippets show how to do that in jetpack compose.
NOTE: The Jetpack Compose team doesn’t recommend passing Parcelable in the navigation composable routes.
In the view system navigation component, we were able to pass parcelable objects as arguments to the destinations, you might be tempted to do that in Compose Navigation as well and write up code that looks like this:
To support Compose, use the following dependency in your app module’s build.gradle file: The NavController is the central API for the Navigation component. It is stateful and keeps track of the back stack of composables that make up the screens in your app and the state of each screen.
Navigation routes are equivalent to urls. Generally you're supposed to pass something like id
there.
When you need to pass a url inside another url, you need to encode it:
val encodedUrl = URLEncoder.encode("http://alphaone.me/", StandardCharsets.UTF_8.toString())
navController.navigate("HistoryDetail/$encodedUrl")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With