Suppose that my app handles all example.com
deep links, but the NavHost
within MainActivity
handles only example.com
, example.com/account
, and example.com/account/detail
, while other paths are forwarded to another activity called WebViewActivity
. How to create a fallback destination that will forward to another activity?
NavHost(navController = navController, startDestination = "root") {
composable(
"root",
deepLinks = listOf(
navDeepLink { uriPattern = "example.com" }
),
) {
}
composable(
"account",
deepLinks = listOf(
navDeepLink { uriPattern = "example.com/account" }
),
) {
}
composable(
"accountdetail",
deepLinks = listOf(
navDeepLink { uriPattern = "example.com/account/detail" }
),
) {
}
other("fallback") { // How?
}
}
What I've tried so far:
Using
example.com/.*
pattern: it takes precedence overaccountdetail
destination.composable( "fallback", deepLinks = listOf( navDeepLink { uriPattern = "example.com/.*" } ), ) { val url = it.arguments?.getParcelable<Intent>(NavController.KEY_DEEP_LINK_INTENT) ?.dataString }
Catching in
home
destination and taking the URL fromActivity.intent
: too hacky.