我有一个看起来像这样的 NavGraph:
@Composable
fun NavGraph (
navController: NavHostController
) {
NavHost(
navController = navController,
startDestination = "Products"
) {
composable(
route = "Products"
) {
ProductsScreen(
navController = navController
)
}
composable(
route = "Product Details",
arguments = listOf(
navArgument("product") {
type = NavType.SerializableType(Product::class.java)
}
)
) {
val product = navController.previousBackStackEntry?.arguments?.getSerializable("product") as Product
ProductDetailsScreen(
navController = navController,
product = product
)
}
}
}
在 ProductDetailsScreen 中,我希望单击产品以进一步导航到传递产品对象的详细信息屏幕:
LazyColumn {
items(
items = products
) { product ->
ProductCard(
product = product,
onProductClick = {
navController.currentBackStackEntry?.arguments?.putSerializable("product", product)
navController.navigate("Product Details")
}
)
}
}
产品完美显示,但当我单击产品时,应用程序因以下错误而崩溃:
java.lang.IllegalArgumentException:与请求匹配的导航目的地 NavDeepLinkRequest{ uri=android-app://androidx.navigation/Product Details } 在导航图中找不到 NavGraph(0x0) startDestination={Destination(0xb543811) route=Products}
任何人都可以帮忙吗?
PS我也跟着这个答案,但没有运气:(