Jorge Domínguez
07/25/2024, 10:25 PMcomposable(
route = Destination.Route,
deepLinks = listOf(
navDeepLink { uriPattern = "/path1" },
navDeepLink { uriPattern = "/path1/{argument1}" },
navDeepLink { uriPattern = "/path2/{argument2}" },
),
)
So when I click on a link like https://www.test.com/path1/123 the app opens the destination correctly, however when I try to do the same thing programmatically by doing:
navController.navigate(Uri.parse(URLEncoder.encode("<https://www.test.com/path1/123>", "UTF-8"))
I get a
java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=https%3A%2F%2Ftest.com%2Fpath1%2F123 } cannot be found in the navigation graph
any idea what I might be doing wrong here?Skaldebane
07/25/2024, 10:29 PM<https://www.test.com/>
) and only keep the path?Jorge Domínguez
07/25/2024, 10:32 PMSkaldebane
07/25/2024, 10:43 PMSkaldebane
07/25/2024, 10:44 PMdeepLinks
uri patternsSkaldebane
07/25/2024, 10:44 PMval uri = "<https://www.example.com>"
composable(
"profile?id={id}",
deepLinks = listOf(navDeepLink { uriPattern = "$uri/{id}" })
) { backStackEntry ->
Profile(navController, backStackEntry.arguments?.getString("id"))
}
Stylianos Gakis
07/25/2024, 11:29 PMIan Lake
07/26/2024, 1:14 AMUri.parse(URLEncoder.encode(
also is very suspect - generally you just pass the string to Uri.parse
- encoding it ahead of time is actually stripping all of the /
and other symbols from the Uri (which is why you see https%3A%2F%2F
for instance). I don't know why you'd encode the whole string (if anything, you'd use Uri.encode
around a single argument)Skaldebane
07/26/2024, 11:53 AMString.toUri()
extension function in androidx, much simplerJorge Domínguez
07/26/2024, 3:08 PMNavDeepLink
does have it, so I added "https://"
to the `uriPattern`s and now it works, however the uri that I pass to navController.navigate()
has to be parsed from a string matching exactly that pattern, so it has to be "<https://www.test.com/path1>"
, it can’t be "<http://test.com/path1|test.com/path1>"
or "<http://www.test.com/path1|www.test.com/path1>"
, which kinda weirds me out because in the test provided by Stylianos the uri string doesn’t have the scheme, is this expected?Ian Lake
07/26/2024, 3:11 PMURIs without a scheme are assumed as either http or https. For example, www.google.com matches both http://www.google.com and https://www.google.com.