title: SwiftUI app goes back to first screen when app is put into the background
body: <p>I have built an app in SwiftUI and have encountered an annoying issue.</p>
  <p>When the app is presented the app shows a custom launch screen while the data of the app loads asynchronously. Once finished, the app's main view is presented to the user. Once the user reaches this point, as soon as they drag the app back into he background the navigation stack pops back to the first launch screen for no reason.</p>
  <p>Here are the relevant code snippets:</p>
  <p>MyApp.swift</p>
  <pre><code>@main
  struct Jam500App: App {
      
      @Environment(\.scenePhase) var lifecycle
  
      init() {
          //initial setup goes here
      }
      
      var body: some Scene {
          WindowGroup {
                  LaunchView()
          }
      }
      
  }
  </code></pre>
  <p>LaunchView.swift</p>
  <pre><code>struct LaunchView: View {
      
      @ObservedObject var control: LaunchViewControl = LaunchViewControl()
      
      var body: some View {
          NavigationView(content: {
              ZStack {
                  //some view hierarchy                 
                  NavigationLink(destination: RootView(),
                                 isActive: $control.isReady,
                                 label: {EmptyView()})
  
              }
              .onAppear(perform: {
                  control.loadData()
              })
              .navigationBarTitle(&quot;&quot;)
              .navigationBarHidden(true)
              .statusBar(hidden: true)
          }).navigationViewStyle(StackNavigationViewStyle())
      }
      
  }
  </code></pre>
  <p>LaunchViewControl.swift</p>
  <pre><code>final class LaunchViewControl: ObservableObject {
      
      @Published var isReady: Bool = false
      private var executing: Bool = false
      private let dataService = DataService.shared
      
      func loadData() {
          //runs all initial app setup needed before the app starts (asynchronously)
          guard !executing else {
              return
          }
          executing = true
          self.setupCoreData()
      }
      
      private func setupCoreData() {
          //Initialises CoreData with CloudKit (asynchronously)
          CloudCoreDataService.shared.setup { [weak self] in
              guard let self = self else { return }
              self.checkRequiresInitialData()
          }
      }
      
      private func checkRequiresInitialData() {
          self.dataService.requiresInitialDataSetup(onCompletion: { [weak self] (isRequired) in
              guard let self = self else { return }
              if isRequired {
                  self.setupInitialData()
              } else {
                  self.isReady = true
              }
          })
      }
      
      private func setupInitialData() {
          //Generates initial database if needed
          self.dataService.setupInitialData { [weak self] (_) in
              guard let self = self else { return }
              self.isReady = true
          }
      }
      
  }
  </code></pre>
  <p>RootView.swift</p>
  <pre><code>struct RootView: View {
      
      @ObservedObject var control = RootViewControl()
      
      var body: some View {
          HStack(spacing: 0) {
              //some view hierarchy
          }
          .navigationBarTitle(&quot;&quot;)
          .navigationBarHidden(true)
          .statusBar(hidden: true)
      }
      
  }
  </code></pre>
  <p>Has anyone else encountered this issue with Xcode 12.4?</p>