Is anyone can tell me where is wrong that my wrote?

import SwiftUI
import Playgrounds

@main struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}


struct AccountView: View{
    var body: some View{
       
            Text("111")
        
    }
}

struct ChatView: View{
    var body: some View{
        
            Text("222")
        
    }
}


struct ProjectView: View{
    var body: some View{
        
            Text("333")
        
    }
}

struct EnvView: View{
    var body: some View{
            Text("444")
        
    }
}



struct ContentView: View {
    var body: some View {
        NavigationSplitView {
            List{
                NavigationLink("Account",value: 1)
                NavigationLink("Chat",value: 2)
                NavigationLink("Project",value: 3)
                NavigationLink("Enviroments",value: 4)
                
            }
        } detail: {
            NavigationStack{
                VStack{
                    Text("SB")
                }
                .navigationDestination(for: Int.self) { number in
                                switch number {
                                case 1: AccountView()
                                case 2: ChatView()
                                case 3: ProjectView()
                                case 4: EnvView()
                                default: Text("未知页面")
                                }
                            }
            }
        }
    }
}

#Preview {
    ContentView()
}

I want to write a sidebar to change pages, I wrote some codes by advices of Deepseek, but it didn't work, it just stay in the VStack under the contentView.

Help me​😭

I wrote some codes by advices of Deepseek

You'd probably better try first to understand the code you are writing.

navigationDestination should come after the List:

        NavigationSplitView {
            List{
                NavigationLink("Account",value: 1)
                NavigationLink("Chat",value: 2)
                NavigationLink("Project",value: 3)
                NavigationLink("Enviroments",value: 4)
                
            }
            .navigationDestination(for: Int.self) { number in
                switch number {
                case 1: AccountView()
                case 2: ChatView()
                case 3: ProjectView()
                case 4: EnvView()
                default: Text("未知页面")
                }
            }

On what device are you testing ? NavigationSplitView shrinks down to a single column when there is not enough room, such as iPhone.

Thanks for the post. You want to open with a new view? What about instead of navigationDestination you use a detail?

NavigationSplitView { { NavigationLink("Account", value: 1) } .navigationTitle("Menu") } detail: { switch here { case 1: AccountView()  } }

the NavigationLink is in the sidebar, but the NavigationStack and .navigationDestination are in the detail area.

I do not know if you want to use a switch but I recommend it, in that case do not forget to add the

switch selection // and then each case

Hope this work, sorry I didn't use Xcode so you'll have to put it all together.

Hope this helps

Albert  WWDR

Is anyone can tell me where is wrong that my wrote?
 
 
Q