I’ve this situation:
Single NavHost and single NavController with this structure:
NavHost(initialRoute = "A"){
navigation(route = "A", initialRoute = "A1") {
composable(route = "A1") {...}
composable(route = "A2") { // This one
ScreenA2()
}
}
navigation(route = "B", initialRoute = "B1") {
composable(route = "B1") {...}
composable(route = "B2") {...}
composable(route = "A2") { // This one
ScreenA2()
}
}
}
Graphs “A” and “B” represents two tabs in my application.
At tab switch, I navigate to routes “A” or “B”, saving and resuming the states to create independents virtual backstacks for each tab.
In my case, I NEED to have the route “A2” in both graph, so I can navigate to A2 from each graph and maintain separate stacks.
The question is: How can I tell to navigate() function to prefer the “A2” screen within the current navigation graph?
Examples:
- I’m in “B1” route and navigating to “A2” the navController should
choose the “B/A2” destination. - I’m in “A1” route and navigating to “A2” the navController should choose the “A/A2” destination.
How can I achieve that?