Missing Destination when "pop to" root View

I have referred to this Stack Overflow thread SwiftUI How to Pop to root view

However it doesn't work for my case, of course no answer fits each persons use case perfectly so one always has to modify the answer slightly but of course keeping to the overall outline of the solution.

The solution I went with is use an ObservableObject and set it as an EnvironmentObject of the root view.

The navigation stack grows by 4 views:

Code Block
RootView().environmentObject(AppSettings.shared)
FirstView()
SecondView()
ThirdView()
FourthView()

The NavigationLink isActive state for the FirstView is defined in AppSettings.shared, all the other states are found in the subsequent view and not in AppSettings.
For example:
FirstView -> SecondView the SecondView isActive state is defined in the ViewModel of the FirstView, and so on and so forth.

What I am trying to achieve is to pop to RootView from the FourthView. So on the FourthView there is an environmentObject variable of type AppSettings (passed down as an EnvironmentObject from RootView) and on button press, toggle RootView -> FirstView isActive state to false.

It toggles but there's no navigation.
However, in the debug console this is the error
Code Block
Trying to pop to a missing destination at /Library/Caches/com.apple.xbs/Sources/Monoceros/Monoceros-42.24.100/Shared/NavigationBridge_PhoneTV.swift:205

From my understanding toggling that state to false should trigger a navigation back, but in the Stack Overflow thread there was a post to use @State variable from RootView -> FirstView and in the EnvironmentObject have a variable moveToDashbord. Then on the RootView add a .onReceive modifier to listen to moveToDashboard publisher and then trigger @State variable. But again that also results in the same debug console message.

In short all solutions result in a missing destination console message. Is this because the navigation is too deep?

This is an iPad only project, and the navigationView style is set to StackedNavigationStyle.

System Details:

Xcode 11.6
iOS/ PadOS Target 13.0 (so not using SwiftUI 2.0, if that is a thing)


Code examples:


This is the SceneDelegate which sets the AppSettings as system wide EnvironmentObject.
Code Block
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let contentView = LoginView().environmentObject(AppSettings.shared)
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
    window.rootViewController = UIHostingController(rootView: contentView)
    self.window = window
    window.makeKeyAndVisible()
  }
}

This is an example of the navigationLink to the RootView
Code Block
NavigationLink(destination: RootView().navigationBarBackButtonHidden(true), isActive: self.$loginViewModel.loginSuccess) {
EmptyView()
}

This is an example of navigationLink from RootView -> FirstView:
Code Block
NavigationLink(destination: FirstView().environmentObject(FirstViewModel()), isActive: self.$appSettings.firstView) {
EmptyView()
}.isDetailLink(false)

Note. I had to change the actual names of the Views for clarification sake.