I have three views, view one ---> view two ---> view three ----> view one
however this leads to a new back button being added every time the view three is reached via view two...
<- back
<- back
<- back
<- back
<- back
how can i avoid this, now i can add .navigationBarBackButtonHidden(true)
but this only hides back button, 15-20 attempts later the navigation crashes ...
If there is a solution please suggest , i would highly prefer to use the NavigationView, thanks
I have followed the advise of having just one NavigationView at root
First View
struct ContentView: View {
@State private var gotoSecond = false
var body: some View {
NavigationView {
VStack {
Text("I am first view")
Button {
gotoSecond = true
} label: {
Text("Go to Second View")
.font(.largeTitle)
}
NavigationLink("", destination: CardView(), isActive: $gotoSecond)
}
}
}
}
SecondView
struct CardView: View {
@State private var gotoFinalView = false
var body: some View {
VStack {
Text(" I am second view")
Button {
gotoFinalView = true
} label: {
Text("Go to final view")
.font(.largeTitle)
}
}
NavigationLink("", destination: FinalView(), isActive: $gotoFinalView)
}
}
Final View
struct FinalView: View {
@State private var gotofirstView = false
var body: some View {
VStack {
Text(" I am final view")
Button {
gotofirstView = true
} label: {
Text("go back to first view")
.font(.largeTitle)
}
}
NavigationLink("", destination: ContentView(), isActive: $gotofirstView)
}
}