I've looked around but haven't seen any info on this. If I want to have multiple navigation stacks in SwiftUI, and have multiple navigation links that add to different navigation stacks, how can I do this? In my use case I use a tab view, so I would be something like:
NavigationStack(path: $globalNavigationStack) {
TabView {
PrimaryView()
SecondaryView()
}
}
Then maybe in PrimaryView:
struct PrimaryView: View {
var body: some View {
NavigationStack(path: $localNavigationStack) {
NavigationLink(value: SomeType.self) {
Button("This should add to local stack")
}
.navigationDestination(for: SomeType.val) { someType in
ViewOnLocalStack()
}
NavigationLink(value: SomeType.self) {
Button("This should add to global stack")
}
.navigationDestination(for: SomeType.val) { someType in
ViewOnGlobalStack()
}
}
}
}
But the second NavigationLink
will add to the local stack. Assuming I have access to the global path, how can I make the second one add to global path? What I tried was this:
NavigationStack(path: $globalNavigationStack) {
TabView {
PrimaryView()
SecondaryView()
}
}
.navigationDestination(for: SomeType.val) { someType in
ViewOnGlobalStack()
}
along with removing the onDestination
from the second link, but the console complained that the navigation link had no corresponding onDestination
. Not sure if I've seen anyone else have a similar situation.
tab
can have aNavigationStack
but aTabView
shouldn't be inside one. They should be "mutually exclusive" per the human interface guidelines. that global stack goes against Apple's design