This is a simple code that I am trying to test for my required feature. I want to be able to click on the button or something to take me back to the FirstView without me needing to click the back button each time.
I found that if I add another NavigationLink() with destination to FirstView() in the ThirdView() then it will stack the FirstView() on top of ThirdView().
The action that I want to perform is
Current Output:
Navigation Stack Before clicking "Go to First View" : FirstView() -> SecondView() -> ThirdView()
Navigation Stack After clicking "Go to First View": FirstView() -> SecondView()
Desired Output:
Navigation Stack Before clicking "Go to First View" : FirstView() -> SecondView() -> ThirdView()
Navigation Stack After clicking "Go to First View": FirstView()
struct FirstView: View {
var body: some View {
NavigationView {
VStack {
Text("First View")
.font(.headline)
.padding()
NavigationLink(destination: SecondView()) {
Text("Go to Second View")
}
}
}
}
}
struct SecondView: View {
var body: some View {
VStack {
Text("Second View")
.font(.headline)
.padding()
NavigationLink(destination: ThirdView()) {
Text("Go to Third View")
}
}
}
}
struct ThirdView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
VStack {
Text("Third View")
.font(.headline)
.padding()
Button(action: {
dismiss()
}) {
Text("Go to First View")
}
}
}
}