Search code examples
swiftmacosswiftuiswiftui-navigationlink

NavigationLink on macOS not opening in the same View


I'm currently building a macOS App with SwiftUI (no Catalyst) that is supposed to have a Sidebar and a single View to the right of it.

NavigationView {
    List {
        ...
    }
    .listStyle(SidebarListStyle())

    HomeView()
}

My Home View has a NavigationLink inside of it, pointing to another DetailView.

struct HomeView: View {
    var body: some View {
        NavigationLink("DetailView", destination: Text("This is the DV"))
    }
}

This NavigationLink always appears as disabled and only works when I add another Column to the NavigationView. I don't want another Column, but rather the NavigationLink replacing the HomeView with the DetailView.

Is there any way to achieve this?


Solution

  • So apparently SwiftUI 2 does not support pushing views on to the Navigation Stack on macOS yet. However, I found this package that helps to resolve the issue:

    github.com/lbrndnr/StackNavigationView