Jetpack 组合导航的多个参数
Multiple arguments with jetpack compose navigation
如何声明具有多个导航参数的导航路线?我已经查看了 documentation, and all of these 篇文章(它们似乎只是重申了文档中的内容),但我只能找到带有一个参数的路由示例。
这是我的:
composable(
route = "createExercise/{exerciseId}",
arguments = listOf(navArgument("exerciseId") { type = NavType.IntType })
) { backStackEntry ->
CreateExerciseScreen(
exerciseId = backStackEntry.arguments!!.getInt("exerciseId"),
)
}
这是我想要的:
composable(
route = "createExercise/{exerciseId},{workoutId}",
arguments = listOf(
navArgument("exerciseId") { type = NavType.IntType },
navArgument("workoutId") { type = NavType.IntType },
)
) { backStackEntry ->
CreateExerciseScreen(
exerciseId = backStackEntry.arguments!!.getInt("exerciseId"),
workoutId = backStackEntry.arguments!!.getInt("workoutId"),
)
}
我为上面的示例随意选择了逗号分隔的语法来代替我正在寻找的真实语法。
所以,我的问题是:在声明导航路线时,多个参数的正确语法是什么? (那么可选参数呢?)
根据文档:
You can think of it as an implicit deep link that leads to a specific destination.
因此它遵循与网络上任何其他 implicit deep link 和 RESTful URL 相同的约定,通常使用 /
来分隔不同的构成 URL 路径的参数 - 这涵盖了所需的参数:
createExercise/{exerciseId}/{workoutId}
根据 optional arguments documentation,所需参数的路径后可以跟一个或多个查询参数形式的任意数量的可选参数:
createExercise/{exerciseId}/{workoutId}?setNumber={setNumber}&repNumber={repNumber}
如何声明具有多个导航参数的导航路线?我已经查看了 documentation, and all of these 篇文章(它们似乎只是重申了文档中的内容),但我只能找到带有一个参数的路由示例。
这是我的:
composable(
route = "createExercise/{exerciseId}",
arguments = listOf(navArgument("exerciseId") { type = NavType.IntType })
) { backStackEntry ->
CreateExerciseScreen(
exerciseId = backStackEntry.arguments!!.getInt("exerciseId"),
)
}
这是我想要的:
composable(
route = "createExercise/{exerciseId},{workoutId}",
arguments = listOf(
navArgument("exerciseId") { type = NavType.IntType },
navArgument("workoutId") { type = NavType.IntType },
)
) { backStackEntry ->
CreateExerciseScreen(
exerciseId = backStackEntry.arguments!!.getInt("exerciseId"),
workoutId = backStackEntry.arguments!!.getInt("workoutId"),
)
}
我为上面的示例随意选择了逗号分隔的语法来代替我正在寻找的真实语法。
所以,我的问题是:在声明导航路线时,多个参数的正确语法是什么? (那么可选参数呢?)
根据文档:
You can think of it as an implicit deep link that leads to a specific destination.
因此它遵循与网络上任何其他 implicit deep link 和 RESTful URL 相同的约定,通常使用 /
来分隔不同的构成 URL 路径的参数 - 这涵盖了所需的参数:
createExercise/{exerciseId}/{workoutId}
根据 optional arguments documentation,所需参数的路径后可以跟一个或多个查询参数形式的任意数量的可选参数:
createExercise/{exerciseId}/{workoutId}?setNumber={setNumber}&repNumber={repNumber}