Home > Mobile >  Navigation destination that matches request NavDeepLinkRequest {...} cannot be found in the navigati
Navigation destination that matches request NavDeepLinkRequest {...} cannot be found in the navigati

Time:10-12

The error occurred when I got so many arguments and I already tried some solutions I read here in StackOverflow but they didn't work in my code. I just want to ask what should I do about the error.

Code:

sealed class NavigationScreen(val route: String) {
    object HeroesPageScreen: NavigationScreen("hero_information_screen")
    object HeroDetails: NavigationScreen("hero_details_screen")

    fun withArgs(vararg args: String): String {
        return buildString {
            append(route)
            args.forEach { arg ->
                append("/$arg")
            }
        }
    }
}

@ExperimentalFoundationApi
@Composable
fun NavigationHero() {
val navController = rememberNavController()

NavHost(navController = navController, startDestination = 
NavigationScreen.HeroesPageScreen.route) {
    composable(route = NavigationScreen.HeroesPageScreen.route) {
        HeroesPageScreen(navController = navController)
    }
    composable(route = NavigationScreen.HeroDetails.route   "/{item}",
        arguments = listOf(
            navArgument("item") {
                type = NavType.StringType
                nullable = true
            })

        ){
            navBackStackEntry ->
        navBackStackEntry.arguments?.getString("item")?.let { json ->
            val item = Gson().fromJson(json, HeroInfoData::class.java)
            HeroDetails(data = item)
            }

        }
    }
}

@Composable
fun HeroCardItem(data: HeroInfoData, navController: NavController) {
    Card(
    modifier = Modifier
        .clickable {
            val itemId = Gson().toJson(data)
            navController.navigate(NavigationScreen.HeroDetails.route   "/$itemId")
        }
        .padding(5.dp)
        .fillMaxSize(),
    elevation = 5.dp,
    shape = RoundedCornerShape(5.dp)
) {...}
}

When I run my code this error occurs:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dota2dict, PID: 7361
java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/hero_details_screen/{"attackType":"MELEE","attackTypeImage":1,"complexityImage":1,"heroDescription":"SHIELDS HIS ALLIES OR HIMSELF FROM ATTACKS","heroHistory":"Able to transform enemy attacks into self-healing, Abaddon can survive almost any assault. Shielding allies and launching his double-edged coil at a friend or foe, he is always ready to ride into the thick of battle.","heroName":"ABADDON\n","heroType":"Strength","imageId":1,"roleCarry":25,"roleDisabler":0,"roleDurable":75,"roleEscape":0,"roleInitiator":0,"roleJungler":0,"roleNuker":0,"rolePusher":0,"roleSupport":75,"statArmor":"2.8","statAttackDamage":"50-60","statAttackRange":"150","statAttackTime":"1.7","statMovementSpeed":"325","statVision":"1800/800","typeImage":1} } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x19e6c117) route=hero_information_screen}

CodePudding user response:

if your json contains url , it happpens but i didn't see url in your's.

try this

composable(route = NavigationScreen.HeroDetails.route   "?item={item}"

navController.navigate(NavigationScreen.HeroDetails.route   "?item=$itemId")
  • Related