Post

Replies

Boosts

Views

Activity

NavigationStack within NavigationSplitView's detail column clears the path when disappearing
I'd like to persist the path on a sidebar selection, so when user comes back to the sidebar selection, they land where they were before. Unexpectedly, the path gets cleared when sidebarSelection is changed from the NavigationStack that uses the path to something else. Is this an intended behavior? How to workaround it? Using TabView is one way, but TabView has its own problems, so I'm wondering if there's a solution within NavigationSplitView first. Here is a minimal reproduce of the issue: struct Home2: View { private enum SidebarSelection: CaseIterable, Identifiable { var id: Self { self } case files, tags } @State private var sidebarSelection: SidebarSelection? = .files @State private var path: [Int] = [] var body: some View { NavigationSplitView { List(SidebarSelection.allCases, selection: $sidebarSelection) { selection in switch selection { case .files: Label("Files", image: "custom.square.stack") case .tags: Label("Tags", systemImage: "grid") } } } detail: { switch sidebarSelection { case .files: NavigationStack(path: $path) { Subview(depth: 1) .navigationDestination(for: Int.self) { Subview(depth: $0) } } case .tags: Text("Tags") default: EmptyView() } } .onChange(of: path) { print("\(path.count)") } } } struct Subview: View { let depth: Int var body: some View { List { NavigationLink("Next: \(depth + 1)", value: depth + 1) } .navigationTitle("Depth \(depth)") } } #Preview("Home2") { Home2() }
4
0
79
May ’25