我正在尝试在用户可以从欢迎页面显示欢迎消息时在仪表板上向用户显示欢迎消息。 因此,在仪表板的路线中,我定义了一个可选参数。
无需任何参数即可访问它,效果很好(因为它是可选的),但是当我添加一个时,它就不再工作了。
composable(Routes.welcome) {
WelcomeScreen {
navController.navigate("dashboard?isWelcome={true}")
}
}
composable(
"dashboard?isWelcome={isWelcome}}",
arguments = listOf(
navArgument("isWelcome") {
type = NavType.BoolType
}
)
) {
val isFromWelcome = it.arguments?.getBoolean("isWelcome") ?: false
...
}
我的错误:
Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/dashboard?isWelcome={true} } cannot be found in the navigation graph
谢谢你的建议:)
val booleanValue = true
navController.navigate("my_destination?my_arg_id=${booleanValue}")
composable(
route = "my_destination?my_arg_id={my_arg_id}",
arguments = listOf(navArgument("my_arg_id") { defaultValue = false })
) { from ->
val myBooleanArg = from.arguments?.getBoolean("my_arg_id")
MySecondScreen(myBooleanArg)
}