Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to navigate in Jetpack Compose if arguments supplied has special characters in it

Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/testScreen/Can I change this (Pin / Password)?/100/300 } cannot be found in the navigation graph

where

Can I change this (Pin / Password)?

is the title for my screen. I get an exception while trying to navigate. How can I avoid this issue as my title contains ' / ' which is getting considered as part of the deeplink itself.

like image 841
Ali_Waris Avatar asked Oct 11 '25 09:10

Ali_Waris


2 Answers

Special characters are not supported in url based navigation in compose.

If you feel there is a special character in your string argument. You can try encoding it to java.util.Base64

val titleArg = Base64.getUrlEncoder().encodeToString(title.toByteArray())

And then send this titleArg as a navigation argument or path

While receiving it just do a decode like this

val title = String(Base64.getUrlDecoder().decode(titleArg))
like image 196
Dr. aNdRO Avatar answered Oct 13 '25 23:10

Dr. aNdRO


In general, using utf8 is better (instead of Base64).

Encoding the argument with

URLEncoder.encode(argument, "utf-8")

and later decoding it with

URLDecoder.decode(backStackEntry.arguments?.getString("argument") ?: "","utf-8")

was enough in my case. This also handles the new lines.

like image 29
YogeshM Avatar answered Oct 14 '25 00:10

YogeshM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!