Hi all, when navigating from what is the differen...
# compose
b
Hi all, when navigating from what is the difference between
Copy code
navController.navigate("nextPage") {
    popUpTo("currentPage") { inclusive = true }
}

//and 
navController.navigateUp()
navController.navigate("nextPage")
i
The first does a single atomic event (and popUpTo is a no-op if currentPage isn't on the back stack, which probably doesn't make a difference in your case). The second one does a
navigateUp()
operation first (which is different from
popBackStack()
in cases where you have deep linked into that destination or any other case where you don't have anything before the current destination on the back stack) then does a separate
navigate()
operation after the
navigateUp()
has completed
In the Compose world, the snapshot system tends to paper over the non-atomic nature of the second one (as you'll only get the final state in the next recomposition)
b
thanks, what is the best practice if i want to close current page and navigate to next page? I am having issue when using (https://github.com/google/accompanist/tree/main/navigation-material) it doesn’t always pop the current page. Which means from next page, when i backclick it still has current page on the stack
i
Your first code with
popUpTo
is the correct code to be using
b
thanks @Ian Lake