In the following example, the NavigationStack path ["one", "two", "three"]
is written to model.path
variable.
When the application loads without TabView
, the deep link works just fine and we end up at page "three", third element in the Stack.
However, if the same NavigationStack using the same stack is contained in a TabView, it breaks.
See the example below, with variable working
not using the TabView
and notWorking
with the TabView
import Foundation
import SwiftUI
class MyModel: ObservableObject {
@Published var path: [String]
init(path: [String] = []) {
self.path = path
}
}
struct MyView: View {
@ObservedObject var model: MyModel
var body: some View {
// working
notWorking
}
var working: some View {
NavigationStack(path: $model.path) {
Form {
Text("Root")
}
.navigationDestination(for: String.self) {
Text($0)
}
}
}
var notWorking: some View {
TabView {
working
}
}
}
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
MyView(
model: MyModel(path: ["one", "two", "three"])
)
}
}
}