I'm trying to create navigation for my app using Navigation Stack and routing. My code is functioning and navigating to views, the problem I'm having is that the view is getting called several times from within a switch statement, I have placed the nav stack in the some scene view, then added a simple link, when tapped it goes through the switch statement and picks up the value 3 times and displays the view, I placed a print statement in the switch and it's printed 3 times for my new view value, following on with database calls etc, they are also getting called 3 times.
I'm new to SwiftUI so I'm sure it's user error, any help would be appreciated, thanks.
enum Routing : Hashable {
case AddFlight
case PilotsList
case newview
}
@State var navPath = NavigationPath()
var body: some Scene {
WindowGroup {
NavigationStack (path: $navPath) {
NavigationLink(value: Routing.newview, label: {Text("Go to new view")})
.navigationDestination(for: Routing.self) { route in
switch route {
case .newview:
Text("New View")
let a = print("New view")
case .PilotsList :
PilotsListView()
case .AddFlight:
AddEditFlightView()
}
}
}
}
}