- Create new SwiftUI project
- Replace ContentView with the code below
- Tap either link.
- Both views are pushed onto the nav stack
class ContentViewModel: ObservableObject {
@Published var navigationPath = NavigationPath()
}
struct ContentView: View {
@StateObject var viewModel = ContentViewModel()
var body: some View {
NavigationStack(path: $viewModel.navigationPath) {
Form {
Section {
VStack {
NavigationLink(value: 1) {
Text("Location")
}
NavigationLink(value: 2) {
Text("Category")
}
}
}
}.navigationDestination(for: Int.self) { route in
switch route {
case 1: Text("Location")
case 2: Text("Category")
default: Text("Unknown")
}
}.navigationTitle("Home")
}
}
}
What am I doing wrong? I would only expect the tapped item to be pushed into the stack.
Removing the
VStack
solves the problem