How to navigate to another view in NavigationView without NavigationButton in SwiftUI?

Viewed 7884

As the questions says I want to navigate to another view without NavigationButton, something like "pushView" and "popView" in UIkit

1 Answers

I consider this more like a work-around for a limitation, but it worked for me:

Add a boolean state variable which defines whether the link is active. E.g.:

@State private var showLinkTarget = false

Add an invisible NavigationLink like this:

NavigationLink(destination: LinkTargetView(), isActive: self.$showLinkTarget ) {
   Spacer().fixedSize() 
}
Related