SwiftUI NavigationStack: navigation explained simply

NavigationStack is the standard for navigation in SwiftUI. Learn value-based links, jumping back in code, and NavigationSplitView for iPad and Mac.

2 min readby Luca Ring

NavigationStack is the standard way to navigate in SwiftUI on iPhone: a list leads to details, details lead to more screens, and the back button comes for free. Since iOS 16, NavigationStack replaces the older NavigationView and finally makes navigation in code simple.

The core idea: instead of hard-wiring which view goes where, you describe destinations as values. SwiftUI turns them into a stack of screens that you can read and change at any time.

Navigate with values, not views

With NavigationLink(value:) a link only points to a value, for example a case of an enum. You decide once, with navigationDestination(for:), which view belongs to it:

enum Route: Hashable {
    case topic(String)
    case settings
}

struct StartView: View {
    @State private var path: [Route] = []

    var body: some View {
        NavigationStack(path: $path) {
            List {
                NavigationLink("Travel", value: Route.topic("Travel"))
                NavigationLink("Settings", value: Route.settings)
            }
            .navigationTitle("Topics")
            .navigationDestination(for: Route.self) { route in
                switch route {
                case .topic(let name): TopicView(name: name)
                case .settings: SettingsView()
                }
            }
        }
    }
}

The benefit: the list knows nothing about the destination views. New destinations go into the enum and the switch, nothing else changes.

Navigate in code and jump back

Because the stack is just an array, you control it like any other array. That's handy after saving a form, for deep links, or for a “Back to overview” button:

path.append(.settings)   // go one level deeper
path.removeLast()        // go back one level
path.removeAll()         // back to the root

If you need different types in the same stack, use NavigationPath instead of an array. It holds any Hashable value and can even be saved through its codable representation, so your app reopens right where people left off.

Where the state should live

In small apps, @State in the root view is enough. As soon as several places trigger navigation, such as a notification or a widget, the path belongs in a shared @Observable model. How that works is explained in @Observable in SwiftUI. If your data comes from SwiftData, pass only the item's ID; more on that in SwiftData: first steps.

iPad and Mac: NavigationSplitView

On large screens, a single stack quickly feels lost. That's what NavigationSplitView is for, with a sidebar and a detail area side by side on Mac and iPad, and automatically collapsed into a stack on iPhone. The detail column can contain its own NavigationStack.

Common mistakes

  • navigationDestination in the wrong place: attach it inside the NavigationStack, not to a single row of a long list.
  • Nested stacks: one NavigationStack per area is enough, otherwise you get duplicate bars.
  • Whole objects as destinations: prefer small, stable values like IDs so navigation stays valid when data changes.
  • SwiftUI NavigationStack
  • navigationDestination
  • NavigationPath
  • NavigationSplitView
  • SwiftUI navigation