0

I haave couple of issues with deep linking with compose navigation.

  1. When deeplink is connected to a screen that is in the main Graph it works just fine if the application is cloed, but if its already open the app does not navigate to the target screen. i set android:launchMode="singleTask" in the manifest.
  2. When i try to open a deep link that is connected to a nested graph i get an exception IllegalArgumentException: navigation destination is not a direct child of this NavGraph

I'm not sure how to aproach these issues, Can anyone help me out?

Here are sample of my code:

Manifest

<activity
    android:name=".MainActivity"
    android:exported="true"
    android:label="@string/app_name"
    android:screenOrientation="userPortrait"
    tools:ignore="LockedOrientationActivity"
    android:launchMode="singleTop"
    android:theme="@style/Theme.App.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="example.com"
            android:scheme="https" />
    </intent-filter>
</activity>

Navigation for destination in home graph

composable(
            route = NavigationScreen.Item.route,
            deepLinks = listOf(navDeepLink {
                uriPattern = "${BuildConfig.DEEP_LINK_URI}/items/{itemId}"
            }),
            enterTransition = flowParentOnTabEnterTransition(),
            exitTransition = flowParentOnTabExitTransition(),
            popEnterTransition = itemPopEnterTransition(),
            popExitTransition = itemPopExitTransition()
        ) {
            it.arguments?.getString("itemId")?.let { itemId ->
                ItemScreen(navController, itemId)
            }
          }

Navigation for destination in nested graph

composable(
    route = NavigationSearch.Tag.route,
    deepLinks = listOf(navDeepLink { uriPattern = "${BuildConfig.DEEP_LINK_URI}/tag/{id}" }),
    arguments = listOf(
        navArgument(ARG_TAG_ID) {
            type = NavType.StringType
        }
    ),
    enterTransition = simpleEnterTransition(),
    exitTransition = simpleExitTransition(),
    popEnterTransition = simplePopEnterTransition(),
    popExitTransition = simplePopExitTransition()

) {
    val tagId = it.arguments?.getString(ARG_TAG_ID)
    TagScreen(navController, tagId)
}
Eitan
  • 1,012
  • 7
  • 25
  • 2
    That error means you've written in the wrong `startDestination` - one that doesn't, character by character, exactly match the `route` of one of its destinations, but you haven't shown any of your graphs or where you construct your `NavHost`. You'll need to include that code. – ianhanniballake Dec 07 '21 at 19:32
  • Does this answer your question? [Compose Navigation - navigation destination ... is not a direct child of this NavGraph](https://stackoverflow.com/questions/69038660/compose-navigation-navigation-destination-is-not-a-direct-child-of-this-na) – Phil Dukhov Dec 08 '21 at 01:34

0 Answers0