由于某种原因,与经常开除相比,清理航行舱位会造成意外估计。 它清除了面前的屏幕实际上消失了。 如果不清除屏幕,你怎么能够重新扎根?
struct ContentView: View {
@State var navigationPath: NavigationPath = NavigationPath()
var body: some View {
NavigationStack(path: $navigationPath) {
ZStack {
Color.red
NavigationLink(value: 0) {
Text("test")
}
}
.navigationDestination(for: Int.self) { _ in
SubView(navigationPath: $navigationPath)
}
}
}
}
struct SubView: View {
@Binding var navigationPath: NavigationPath
var body: some View {
ZStack {
Color.green
Button {
navigationPath = NavigationPath()
} label: {
Text("back")
}
}
}
}