I am building a macOS SwiftUI app in which I need to perform navigation from my View A to View B. Here is a small screenshot.
Here is my implementation:
struct ViewA: View {
var body: some View {
VStack {
Text("VIEW A")
Button("Go to View B") {
// I want to go to View B and also pass some data to View B
}
}
}
}
struct ViewB: View {
let data: String
var body: some View {
VStack {
Text("VIEW B")
}
}
}
struct ContentView: View {
@EnvironmentObject var appState: AppState
var body: some View {
NavigationView {
SideBar()
ViewA()
}
}
}
In iOS I would use NavigationLink, but for macOS apps NavigationLink is not working as expected. Any ideas?