SwiftUI Unexpectedly NavigationLink pops automatically

1.6k views Asked by At

I have a simple use case where a screen pushes another screen using the NavigationLink. There is a strange behaviour iOS 14.5 where the pushed screen is popped just after being pushed.

Code:

NavigationLink(destination: EmptyView()) { EmptyView()} 

I manage to create a sample app where I reproduce it. I believe the cause is the presence of @Environment(\.presentationMode) that seem to re-create the view and it causes the pushed view to be popped.

The exact same code works fine in Xcode 12 / iOS 14.4

1

There are 1 answers

0
Ishani Patel On BEST ANSWER

I was stuck in this since last week. To fix, I simply added this to my view containing my existing NavigationLinks:

NavigationLink(destination: EmptyView()) {
    EmptyView()
}