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).