Abhishek Dewan
03/02/2022, 6:39 AMoverride fun navigateToHome() {
navController.navigate(RootScreen.Home.route) {
val popUpRoute = navController.currentBackStackEntry?.destination?.route ?: ""
popUpTo(popUpRoute) {
inclusive = true
}
}
}
I would like to make sure that I can clear the back stack completely and then navigate to home. The way I understand navigation, calling popUpTo(currentScreenOnBackStack) should clear all the backstack before we navigate to Home and should account for both scenarios above. I’m sure I’m misunderstanding something obvious. Would appreciate if someone could point it out for me.Csaba Szugyiczki
03/02/2022, 7:54 AMSplash -> Landing -> Sign_In
the code you posted navigates to the Home route, and when you say navController.currentBackStackEntry?.destination?.route
that is basically your current route which is the Sign_In
route currently.
So your popUpTo will pop your current back stack up until the Sign_In
route including the Sign_In
route itself. But your Splash and Landing route will not be affected. What you want to do in both case 1 and 2 is passing the Splash
route to the popUpTo as a parameter, so in both cases you will basically pop every screen off the back stack and then have only your Home
route in it after the navigationAbhishek Dewan
03/02/2022, 3:17 PM