struct View1: View {
var category: String
var body: some View {
NavigationStack {
List { ...
NavigationLink(value: category) {
Text("Link to View2")
}
}
.navigationDestination(for: String.self) { str in
View2(item: str)
}
}
}
}
struct View2: View {
var item: String
var body: some View {
NavigationStack {
List { ...
NavigationLink(value: category) {
Text("Link to View3")
}
}
.navigationDestination(for: String.self) { str in
View3(number: str)
}
}
}
}
struct View3: View {
var number: String
var body: some View {
List { ... }
}
}
In this code View1 when press one of the List item it says " there is no matching navigationDestination declaration visible from the location of the link. " But when I delete the NavigationStack bracket in the View2, then it works. Why is that?
And I want to put the path to the NavigationStack for going to the root. So I think I should leave the NavigationStack in the View2. Is it right? or is there another way?