.navigationDestination(for: String.self){ selection in
if(selection == "login"){
Login(path: $path)
}else if(selection == "register"){
CreateAccount(path: $path)
}
}
.onChange(of: path) { _ in
if(path[path.count - 1] == "login" && path[path.count - 2] == "register"){
// if current view is login and the last one register, close register
path.remove(path.count - 2)
}
if(path[path.count - 1] == "register" && path[path.count - 2] == "login"){
// if current view is register and the last one login, close login
path.remove(path.count - 2)
}
}
What I have inside onChange
is non working pseudo code which should make it easier to understand what I need.
So basically I need to check which views are open and close specific ones.