SwiftUI navigation with buttons, can it be done should it be done?

Hello All,


I'm trying to navigate to a new viewvia a SwiftUI Button, can it be done? or should i be using navigation views?


HStack() {
                    Button(action: { }) {
                        Text("Staff")
                    }.frame(width: 150, height: 75).background(Color.purple).cornerRadius(10).shadow(radius: 5).foregroundColor(Color.white)
                    Button(action: {}) {
                        Text("Visitor")
                    }.frame(width: 150, height: 75).background(Color.purple).cornerRadius(10).shadow(radius: 5).foregroundColor(Color.white)
                }


i would like to have each button navigate to its own view, if possible. I'm new to SwiftUI but i have done this same thing using segues and identifiers o im sure there is a way to accomplish this.

This can be done if you're planning to present a view using a sheet.

However, if you're wanting to use a NavigationView, you should use a NavigationLink instead of a Button.

You can specify the destination view and label for a NavigationLink, just make sure your main view is wrapped in a NavigationView for this to work properly. Child / Destination views shouldn't be wrapped in NavigationView's themselves.

SwiftUI navigation with buttons, can it be done should it be done?
 
 
Q