I want to go from View PathD to PathB in the NavigationStack withOut creating a new Object of PathB and also not removing the view instance of PathC that is in the Navigation Stack Hierarchy.
Details:
@State var path: [String] = []
// or this can also be written
//@State var path: NavigationPath = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
ZStack{
Text("SomeThing")
}
.navigationDestination(for: String.self, destination: { path in
switch path {
case "pathA" :
PathA().navigationBarBackButtonHidden()
case "pathB":
PathB().navigationBarBackButtonHidden()
case "pathC":
PathC().navigationBarBackButtonHidden()
default:
PathD().navigationBarBackButtonHidden()
}
})
here what I tried is matching the reference name when navigation is done in some view
path.append("pathA")
now consider I am in view PathD(). And I want to navigate back to PathB. one option is to slide around but I am disabling the navigation back button.
so what I do is
from PathD
path.append("pathB")
This will create a new PathB() view instead of returning to the one I have.
Now my requirement is to go back to the PathB() that I created and not a new object.
feel free to comment if my explanation is not sufficient