I have a View with a NavigationLink
. This NavigationLink
is a 'logout' button, so when the user clicks this, I don't want them to be able to click the "Back"
button in the NavigationBar
. Is there a way to programmatically change view, and remove the "parent" view.
Here is the view with logout button:
struct SettingsView: View {
@State private var didLogout: Bool = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Login(), isActive: $didLogout) {
Button(action: {
//logout code here
self.didLogout = true
}) {
Text("Logout")
}
}
}
}
}
}
Here is the login view (the view I am pushing to when user logs out):
struct Login: View {
//Login states
@State var isActive = false
@State var attemptingLogin = false
@State var didLoginFail = false
var body: some View {
NavigationView {
VStack {
if (attemptingLogin == true) {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
}
NavigationLink(destination: blah(), isActive: $isActive) {
Button(action: {
attemptingLogin = true
blah.Login() { didLogin in
if didLogin == true {
self.isActive = true
} else {
self.isActive = false
self.didLoginFail = true
self.attemptingLogin = false
}
}
}) {
Text("Login")
}
}
}.padding()
}
}
}
I've removed a few bits of code that aren't required for the question. Any help would be greatly appreciated, as I can't find anything online for this issue. I feel like I'm just not wording my queries correctly, as I'm sure many have run into this issue before with SwiftUI.
Like I said, if there is a way to "forget" the history of the NavigationView, and treat this as the top view in the stack?