0

My problem is as I described it in the title.

I have tried the code below but it's adding a nav bar instead of pushing back the view and returning directly to RootView .

Thank you for your help :)

import SwiftUI

struct RootView: View {
   var body: some View {
       NavigationView{
           NavigationLink(
               destination: View1(),
               label: {
                   Text("Navigate to view1")
               })
           
           
       }
   }
}


struct View1: View {
   var body: some View {
       NavigationLink(
           destination: View2(),
           label: {
               Text("Navigateto view2")
           })    }
}

struct View2: View {
   var body: some View {
       NavigationLink(
           destination: RootView(),
           label: {
               Text("Navigateto Root")
           })
   }
}




struct ContentView_Previews: PreviewProvider {
   static var previews: some View {
       RootView()
   }
}
  • 1
    I don't think you can do it easily with `NavigationView`. You can use `NavigationStack` but it is ios16 only – Paulw11 Jan 25 '23 at 22:49
  • Does this answer your question? [How can I pop to the Root view using SwiftUI?](https://stackoverflow.com/questions/57334455/how-can-i-pop-to-the-root-view-using-swiftui) – timbre timbre Jan 26 '23 at 00:07

0 Answers0