Android Compose导航:在导航图NavGraph中找不到与请求NavDeepLinkRequest匹配的导航



我正在尝试创建一个小型应用程序,该应用程序列出Download文件夹中的PDF文档,当单击文档时,我希望它显示一个可与文档组合的文件,供用户查看。然而,我得到了以下错误:

java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/document/file:///storage/emulated/0/Download/Get_Started_With_Smallpdf.pdf } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0xb86ce466) route=documentList}

这是我的NavHost定义:

NavHost(
navController = navController,
startDestination = "documentList"
) {
composable("documentList") {
DocumentList(
documentList = documentList ?: emptyList(),
onDocumentClicked = { uri ->
navController.navigate("document/$uri")
})
}
composable(
"document/{documentUri}",
arguments = listOf(navArgument("documentUri") {
type = NavType.ParcelableType(Uri::class.java)
})
) { navBackStackEntry ->
navBackStackEntry.arguments?.getParcelable<Uri>("documentUri")
?.let { documentUri ->
PdfDocumentView(uri = documentUri)
}
}
}

在传递之前,我已经尝试将URI编码为String,所以我不必摆弄NavType.ParcelableTypebut with aNavType.StringType`,但结果是一样的。

您在参数字符串中使用特殊字符,这与Jetpack Compose Navigation解析目的地路线的方式相冲突。

对参数进行编码/解码可能是一种解决方案,例如使用Gson或Base64。

最新更新