this is my nav graph
NavHost(navController, startDestination = Splash) {
composable<Splash> { SplashScreen(navController) }
navigation<Home>(startDestination = Editor) {
composable<Editor> { navBackStackEntry->
val data= navBackStackEntry.toRoute<Home>() // right way crash app
val path = navBackStackEntry.arguments?.getString("path") // workaround works fine
....
}
serialized objects:
@Serializable
object Splash
@Serializable
data class Home(val path: String)
@Serializable
object Editor
Problem:
When navigating from the Splash screen to Home using navController.navigate(route = Home("my path")), I am unable to access the path argument in the Editor composable like this: 'navBackStackEntry.toRoute()'.
After some research, I realized that the issue arises because Editor is not the destination of the navigation in the first instance (it's Home that is), so it's not possible to directly retrieve arguments from Editor even though the path argument is available in the bundle. While I can access it via navBackStackEntry.arguments?.getString("path"), I am wondering if there is a more robust solution.