Search code examples
androidandroid-jetpack-composeandroid-jetpack-navigation

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.


Solution

  • 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))