hello, I’m trying to rely on the `NavHost` to hand...
# compose
c
hello, I’m trying to rely on the
NavHost
to handle deeplinks with type safe generated routes but it breaks when there is a trailing slash, here’s a simple example:
Copy code
@Serializable
data class CategoryScreen(val categoryPath: String) : AppNavigationScreen

composable<CategoryScreen>(deeplinks = listOf(
    navDeepLink(basePath = "<myscheme://category>")
)) { ... } 

// <myscheme://category/my-category> -> works ✅
// <myscheme://category/my-category/> -> doesn't ❌
anyone knows how to handle that properly ?
I think I found a workaround but I don’t really like having almost the same logic with one behaviour used automatically and almost the same used explicitly (also it’s pretty ugly):
Copy code
LaunchedEffect(Unit) {
    if (intent.data?.path.orEmpty().endsWith("/")) {
        val uri = intent.data?.buildUpon()?.path(intent.data.path?.removeSuffix("/"))?.build() 
            ?: return
        val intent = Intent(Intent.ACTION_VIEW, uri)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
        navController.handleDeepLink(intent)     
    }
}
c
According to https://datatracker.ietf.org/doc/html/rfc3986 those URL’s are not requesting the same resource. the first one is accessing the
my-category
path the other one is accessing an empty path. from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
```A path consists of a sequence of path segments separated by a slash
("/") character. A path is always defined for a URI, though the
defined path may be empty (zero length)```
If you want to treat them as the same, I assume you’ll need a “hack” like you did.