I'm having following trouble using NavigationView in SwiftUI.
I have a NavigationView embed in a TabView as follow:
var body: some View {
TabView {
NavigationView {
View1()
}
.tabItem { Text("View 1") }
.tag(1)
View2()
.tabItem {Text("View 2") }
.tag(2)
}
}
On the first tab, I have push several views to the NavigationView, but when switch to the second tab and then switch back to the first tab, the NavigationView become View1() again, all pushed views are erased. Demonstrated as bellow:
Expected behaviour is when switching to the first tab, the Payment view is showed instead of HomePage.
Is there anyway to put the state of NavigationView to an external @EnvironmentObject, for example, so that the state of NavigationView remain the same after switching.
