android - 将 URL 作为参数传递给 Jetpack Compose Navigation
问题描述
我HistoryDetail
在我的应用程序中为屏幕创建了一个目的地。
composable(
route = "HistoryDetail/{webpage}",
arguments = listOf(
navArgument("webpage") {
type = NavType.StringType
}
),
) { entry ->
val text = entry.arguments?.getString("webpage") ?: ""
}
当我尝试通过调用导航到该屏幕时:
navController.navigate("HistoryDetail/http://alphaone.me/")
我收到illegalArgumentException
以下消息。
java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/HistoryDetail/http://alphaone.me/ } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x78c9ba0c) route=Home}
编辑:
如果我打电话,它会起作用:navController.navigate("HistoryDetail/test")
。
解决方案
导航路线相当于 url。一般来说,你应该通过类似id
那里的东西。
当您需要在另一个 url 中传递一个 url 时,您需要对其进行编码:
val encodedUrl = URLEncoder.encode("http://alphaone.me/", StandardCharsets.UTF_8.toString())
navController.navigate("HistoryDetail/$encodedUrl")
推荐阅读
- c# - Windows 窗体:具有不同数据源的 DataGridView 中的 ComboBoxColumn
- scala - 用分区内的数据训练分类器
- c# - 将列表 <> 保存在 .txt 文件中
- python - 如何删除 discord.py 中具有其 ID 的频道?
- google-app-engine - Google Appengine:来自 App Engine 的我的 SQL 通信链接失败
- android - 双向绑定 - 数据绑定 Android
- c# - 更改 Pocket PC 时间和日期 c#
- python - ImportError:导入 QtCore、QtGUI 时 DLL 加载失败
- matlab - 在matlab中绘制颜色图
- python - 在熊猫中删除重复项时出现内存错误