0

In my SwiftUI project with deployment target iOS 14, I have a RootView with sub-view View1 in the below formate. How to programmatically navigate back to RootView with View1 from View3.

struct RootView: View {
    var body: some View {
        VStack {
            if condition1 {
                View1()
            } else {
                SomeOtherView()
            }
        }
    }
}

struct View1: View {
    var body: some View {
        NavigationLink to -> View2
    }
}

struct View2: View {
    NavigationLink to --> View3
}
Cheolhyun
  • 169
  • 1
  • 7
Teja Kumar Bethina
  • 3,486
  • 26
  • 34
  • Does this answer your question? [NavigationStack iOS16 with Route, how to pop back to root?](https://stackoverflow.com/questions/76079519/navigationstack-ios16-with-route-how-to-pop-back-to-root) – lorem ipsum May 12 '23 at 13:30
  • NavigationPath is only available in iOS 16 and above. But, as we should support iOS 14 it will not work. Thanks. – Teja Kumar Bethina May 12 '23 at 13:38
  • So is `NavigationStack` (mentioned in your question). There is no built in way to do it with `NavigationView` some people have workarounds you can find on SO with `isActive` – lorem ipsum May 12 '23 at 13:39
  • 2
    I recommend you refer to the following answers : https://stackoverflow.com/questions/57334455/how-can-i-pop-to-the-root-view-using-swiftui – Cheolhyun May 12 '23 at 14:34

0 Answers0