'Dismiss Presentation View - SWIFTUI

I am trying to build a app. I am using presentation mode to show the view, then I switch to another but when I use the dismiss function it just takes me back to the first view.

 struct ContentView: View {
    
    @Environment(\.presentationMode) var presentationMode
    @State private var isShowingBookingScreen:Bool = false
    
    var body: some View {

        Button {
            isShowingBookingScreen = true
        } label: {
            Spacer()
            Text("Book Now").foregroundColor(.white).padding().font(.headline)
            Spacer()
        }.sheet(isPresented: $isShowingBookingScreen) {
            SecondView()
        }.background(Color.accentColor).cornerRadius(10).padding()
    }
}


struct SecondView: View {
    
    var body: some View {
        
        NavigationView{
            NavigationLink(destination:ThirdView()) {
                Text("Continue to Third").foregroundColor(.red).padding().cornerRadius(10).padding()
            }
        }
    }
}


struct ThirdView: View {
    @Environment(\.presentationMode) var presentationMode
    
    var body: some View {            
        Button {
            presentationMode.wrappedValue.dismiss()
        } label: {
            Text("Dismiss")
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source