Hi! I’m using navigation-compose alpha06 and havin...
# compose
t
Hi! I’m using navigation-compose alpha06 and having crashes whenever I tried to popBackStack from a nested navigation. Does anyone having the same issue? Sample code in 🧵
The error is because this line
Copy code
hiltViewModel(navController.getBackStackEntry("b")
Whenever I tried to popBackStack from
nestedB
got this error
Copy code
java.lang.IllegalArgumentException: No destination with route b is on the NavController's back stack. The current destination is Destination(0xe5901274) route=a
i
Sounds like the same issue as https://kotlinlang.slack.com/archives/CJLTWPH7S/p1628012256418100?thread_ts=1628012256.418100&cid=CJLTWPH7S where you aren't taking into consideration that the animations between destinations mean you're going to recompose multiple times even after you are popped (for the fade exit animations)
Have you tried wrapping your call to
getBackStackEntry()
in a
remember
?
t
Not yet. I’ll try it
👍 1
I tried this but no luck
Copy code
navigation(startDestination = "nestedB", route = "b") {
                        composable(route = "nestedB") {
                            val backStackEntry = remember {navController.getBackStackEntry("b")}
                            ComposableB(navController = navController, hiltViewModel(backStackEntry))
                        }
                        composable(route = "nestedC") {
                            val backStackEntry = remember {navController.getBackStackEntry("b")}
                            ComposableC(navController = navController, hiltViewModel(backStackEntry))
                        }
                    }
it throws
Copy code
java.lang.IllegalStateException: You cannot access the NavBackStackEntry's ViewModels until it is added to the NavController's back stack (i.e., the Lifecycle of the NavBackStackEntry reaches the CREATED state).
i
Ah, I missed that you were accessing the nested graph, that'd be the same issue as this thread: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1626962860278800?thread_ts=1626960240.270300&cid=CJLTWPH7S
Which resulted in this issue which we're tracking: https://issuetracker.google.com/issues/194313238
t
Oh! Thank you! I’ll will comment on the duplicated issue of mine.