// // 2ndScreen.swift // NavStackTest // // Created by samileltec on 1/14/25. // import SwiftUI struct SecondScreen: View { @State var path2: [String] = [] @Binding var path: [String] var body: some View { NavigationStack(path: $path2) { VStack { Text("2nd Screen is loaded") Spacer() Button(action: { path2.append("3rd") } , label: { Text("go to 3rd Screen") }) Button(action: { path2.removeLast() } , label: { Text("back to 1st Screen") }) } .navigationDestination(for: String.self) { s in if s == "3rd" { // Text("3rd") thirdScreen() } else { thirdScreen() } } } .onAppear { print("2nd screen on appear") print("2nd screen path = \(path)") print("2nd screen path2 = \(path2)") } .onDisappear { print("2nd screen on disappear") print("2nd screen path = \(path)") print("2nd screen disa. path2 = \(path2)") } } } // #Preview { // SecondScreen() // }