How do I navigate with NavigationStack, NavigationSplitView, and deep links?

In SwiftUI, navigating with `NavigationStack`, `NavigationSplitView`, and handling deep links can enhance your app's user experience. Below, we'll explore how to implement these features effectively.

NavigationStack, NavigationSplitView, deep links, SwiftUI navigation
This guide provides examples of using NavigationStack and NavigationSplitView in SwiftUI, along with techniques for handling deep links in your app.

// Example of using NavigationStack with deep links
import SwiftUI

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    // Handle deep link here
                }
        }
    }
}

struct ContentView: View {
    var body: some View {
        NavigationStack {
            NavigationLink(destination: DetailView()) {
                Text("Go to Detail View")
            }
            .navigationTitle("Home")
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Detail View")
            .navigationTitle("Details")
    }
}
    

// Example of using NavigationSplitView
struct SplitView: View {
    var body: some View {
        NavigationSplitView {
            List(0..<10) { item in
                NavigationLink(destination: Text("Detail for item \(item)")) {
                    Text("Item \(item)")
                }
            }
        } detail: {
            Text("Select an item")
        }
    }
}
    

NavigationStack NavigationSplitView deep links SwiftUI navigation