【发布时间】:2021-11-23 18:32:28
【问题描述】:
从docs,我看到您可以像这样嵌套导航图:
NavHost(navController, startDestination = "home") {
...
// Navigating to the graph via its route ('login') automatically
// navigates to the graph's start destination - 'username'
// therefore encapsulating the graph's internal routing logic
navigation(startDestination = "username", route = "login") {
composable("username") { ... }
composable("password") { ... }
composable("registration") { ... }
}
...
}
我想知道,如何在路由中传递参数,并将其提供给导航图中的所有可组合项?
这是我目前的导航图:
navigation(
// I'd like to grab this parameter
route = "dashboard?classId={classId}",
startDestination = Route.ScreenOne.route) {
composable(Route.ScreenOne.route) {
// And then pass the parameter here, or to any composable below
ScreenOne(classId)
}
composable(Route.ScreenTwo.route) {
ScreenTwo()
}
composable(Route.ScreenThree.route) {
ScreenThree()
}
}
我基本上是在尝试避免在每个可组合路由上单独设置 classId 导航参数。我没有看到像在composable() 中那样将参数列表传递给navigation() 的方法。
可能我所描述的是不可能的,但期待任何人的想法!
【问题讨论】:
标签: android android-jetpack-compose jetpack-compose-navigation