diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt index f40fb0dc0..23ff1edc7 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/navigation/NiaNavHost.kt @@ -44,7 +44,7 @@ fun NiaNavHost( val navController = appState.navController NavHost( navController = navController, - startDestination = ForYouDestination(linkedNewsResourceId = null), + startDestination = ForYouDestination(), modifier = modifier, ) { forYouScreen(onTopicClick = navController::navigateToInterests) diff --git a/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt b/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt index 4d2799444..a5ca0b838 100644 --- a/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt +++ b/feature/foryou/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/navigation/ForYouNavigation.kt @@ -30,14 +30,17 @@ const val LINKED_NEWS_RESOURCE_ID = "linkedNewsResourceId" private const val DEEP_LINK_BASE_PATH = "$DEEP_LINK_SCHEME_AND_HOST/$FOR_YOU_PATH" -@Serializable data class ForYouDestination(val linkedNewsResourceId: String?) +@Serializable data class ForYouDestination(val linkedNewsResourceId: String? = null) +// For deeplinks the news resource ID cannot be null so we use a different type with the same +// argument name to enforce this requirement. +@Serializable data class ForYouDeeplink(val linkedNewsResourceId: String) -fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouDestination(linkedNewsResourceId = null), navOptions) +fun NavController.navigateToForYou(navOptions: NavOptions) = navigate(route = ForYouDestination(), navOptions) fun NavGraphBuilder.forYouScreen(onTopicClick: (String) -> Unit) { composable( deepLinks = listOf( - navDeepLink(basePath = DEEP_LINK_BASE_PATH), + navDeepLink(basePath = DEEP_LINK_BASE_PATH), ), ) { ForYouRoute(onTopicClick)