UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Navigation Issue with Sidebar on MacOS

Forums > SwiftUI

I do have an app with a sidebar where I place my main navigation. When I navigate from the sidebar my DetailView is shown next to the sidebar as it should. But when I want to navigate from my MainView to a DetailView it's not working. The view is only shown as an overlay.

Is there any way I can navigate around my main window from the sidebar and from the main view itself?

import SwiftUI
@main
struct NavigationTestApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                ContentView()
                MainView()
            }
        }
    }
}
struct ContentView: View {
    var body: some View {
        List {
            NavigationLink(
                destination: DetailView(),
                label: {
                    Text("DetailView")
                })
        }
        .listStyle(SidebarListStyle())
    }
}
struct MainView: View {
    var body: some View {
        NavigationLink(
            destination: DetailView(),
            label: {
                Text("Navigate") /* Navigation does not work properly here*/
            })
            .frame(width: 1280, height: 720)
    }
}
struct DetailView: View {
    var body: some View {
        Text("DetailView")
            .frame(width: 1280, height: 720)
    }
}

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.