Hello I have a question regarding Compose Navigati...
# compose
t
Hello I have a question regarding Compose Navigation: For
NavController.navigate
inside the
popUpTo
function, what's the difference between passing in 1.
NavController.graph.findStartDestination().id
and 2.
NavController.graph.id
? I suppose both options points at the root of the
NavGraph
? 🤔
i
Did you get a chance to read the KDocs on
findStartDestination
? It explicitly calls out where they are different (when the start destination of your graph is a nested navigation graph itself): https://developer.android.com/reference/kotlin/androidx/navigation/NavGraph#(androidx.navigation.NavGraph).findStartDestination()
👌 1
t
Thanks for the reply! > (
findStartDestination
) > Finds the actual start destination of the graph, handling cases where the graph's starting destination is itself a NavGraph Can I understand "actual start destination", as "first non-NavGraph destination"?
I have created a test to demonstrate the difference between
startDestinationId
and
findStartDestination().id
Here is a screenshot, I hope this helps people in the future
I still don't understand the exact behavior when using
popUpTo
with
graph.id
kdoc on `NavGraph`: > A NavGraph serves as a 'virtual' destination: while the NavGraph itself will not appear on the back stack, navigating to the NavGraph will cause the [starting destination]_*[getStartDestination]*_ to be added to the back stack. I suppose
popUpTo
with
graph.id
pops the entire back stack, and then adds the start destination to the back stack? And what happens with
inclusive = true
?