NavigationSplitView and NavigationStack persistence

Let's say you have a NavigationModel that contains three NavigationPaths, one for each option in the sidebar for a NavigationSplitView.

This NavigationModel is created by the App and passed down to the root view for the scene in its environment.

Each option has a separate NavigationStack and is passed a binding to the appropriate NavigationPath from the NavigationModel.

Is it expected that when the user changes the selection in the sidebar, the NavigationPath for the newly selected view should be erased?

This is what's currently happening on macOS 26. It seems like the default action when creating a NavigationStack and passing it a binding to a NavigationPath is to clear that path and start from the root view.

Is this normal, intended behaviour or is it a bug? Or, perhaps, an option or modifier I am missing?

@gravity_gunner

Each option has a separate NavigationStack and is passed a binding to the appropriate NavigationPath from the NavigationModel.

Why do you multiple stacks as the detailView of your split view?

To understand the issue better please share a sample code that implements what you've described, that way we're on the same page and please review Understanding the navigation stack

You would have one NavigationStack per sidebar item.

struct RootView: View {
    
    @Environment(NavigationModel.self) var navigationModel
    
    var body: some View {
        @Bindable var navigationModel = self.navigationModel

        NavigationSplitView {
            List(selection: $navigationModel.selectedItem) {
                Label("One", systemImage: "folder")
                    .tag(SidebarItem.one)
                Label("Two", systemImage: "folder")
                    .tag(SidebarItem.two)
            }
            .listStyle(.sidebar)
        } detail: {
            switch navigationModel.selectedItem {
            case .one:
                NavigationStack(path: $navigationModel.pathOne) {
                    OfficersView()
                }
            case .two:
                NavigationStack(path: $navigationModel.pathTwo) {
                    OfficersView()
                }
            }
        }
    }
}

A good example of this in practice is the Apple Music app on macOS. Note how each item in the (long) sidebar has its own NavigationStack and how you can leave and return to any one of those items and the path is retained?

Further investigation and some help from others has turned up this and this.

If I remove the two Labels in the List in the sidebar and remove the selection parameter, and replace the list items with buttons with actions that directly change the navigationModel.selectedItem property, the problem goes away and both NavigationPaths are retained. Though, obviously, this breaks the appearance of the sidebar.

I'm now convinced that this is a defect. Changing navigationModel.selectedItem via the selection parameter on List is somehow resetting the value of the NavigationPath for the relevant NavigationStack as well. This is unexpected behaviour.

For the record, the Understanding the Navigation Stack article you linked to makes no mention of sidebars, NavigationSplitView or TabViews with the .sidebarAdaptable appearance (which also exhibits the same buggy behaviour).

NavigationSplitView and NavigationStack persistence
 
 
Q