title: SwiftUI - Removing a NavigationView?
body: <p>The root view of my onboarding process has a NavigationView. The root view of my app is a login page that also contains a NavigationView.  That means when someone launches the app for the first time, they will go through the onboarding process and land at the login screen - resulting in a navigation view within a navigation view.</p>
  <p>Is there a way to reset the view stack or simply remove the extra navigation view when necessary?</p>
  <hr>
  This is how I implemented @New Dev's solution below. First comes the Tower class. (The name helps me visualize the fact that it's an ObservableObject.) Its job is to keep track of the currentPage and let interested views know when it has changed.
  <pre><code>import Foundation
  import SwiftUI
  import Combine
  
  class Tower: ObservableObject {
      enum Views {
         case onboarding, login, dashboard
      }
      let objectWillChange = PassthroughSubject&lt;Tower, Never&gt;()
      @Published var currentPage: Views = .onboarding {
          didSet {
              objectWillChange.send(self)
          }
      }
  }
  </code></pre>
  <p>Next comes the ConductorView. It is notified by the Tower when currentPage changes, and loads the corresponding view.</p>
  <pre><code>struct ConductorView: View {
  @EnvironmentObject var tower: Tower
      var body: some View {
          VStack {
              if tower.currentPage == .onboarding {
                  ContentViewA()
              } else if tower.currentPage == .login {
                  ContentViewB()
              }
          }
      }
  }
  </code></pre>
  <p>And lastly, a content view.</p>
  <pre><code>struct ContentViewA: View {
      @EnvironmentObject var tower: Tower
      var body: some View {
          Button(action: {
              self.tower.currentPage = .login
              }) {
              Text(&quot;Go to Login&quot;)
              }
          }
      }
  }
  </code></pre>
  <p>In addition to New Devs greatly appreciated solution, I also used <a href="https://blckbirds.com/post/how-to-navigate-between-views-in-swiftui-by-using-an-environmentobject/" rel="nofollow noreferrer">this article</a> from BLCKBIRDS.</p>