NavigationLink opens in DetailView instead of ContentView in NavigationSplitView

53 views Asked by At

I have in my ContentView toolbar with following code:

struct ContentView: View{
    var body: some View {
        ZStack{
            if selectedMailbox == nil {
                ContentUnavailableView("No department selected", systemImage: "tray")
            } else {
                VStack{
                    if isLoading {
                        LoadingView()
                    } else {
                        if searchResults.count > 0 {
                            ScrollView{
                                LazyVGrid(columns: columns, spacing: 5) {
                                    ForEach(searchResults, id:\.id) { ticket in
                                        NavigationLink(value: ticket){
                                            HeaderViewCell(item: ticket)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }.navigationDestination(for: Ticket.self) { ticket in
                    DetailView(selectedTicket: ticket)
                }
            }
        }
    }
    .toolbar {
        ToolbarItem(placement: .topBarTrailing){
            NavigationLink {
                SearchView()
            }  label: {
                Image(systemName: "waveform.and.magnifyingglass")
            }
        }
    }
}

As soon as I tap button in toolbar, it opens its SearchView in DetailView but I need it to replace contents of ContentView. How should I make it?

Thanks Robert

0

There are 0 answers