watchOS NavigationLink not hidden when isActive is false

I'm trying to have a navigation link that is triggered programatically. If I use the following code, on iOS, then the second NavigationLink is not put into the UI, as expected. On watchOS, however, there's a visible button with no text.

How can I accomplish this on watchOS?

Code Block swift
var body: some View {
  NavigationView {
    VStack {
      NavigationLink("No login required", destination: UnprotectedView())
      NavigationLink(destination: ProtectedView(), isActive: $isActive) {
        EmptyView()
      }
      Button("Login required", action: pushIfAuthenticated)
    }
    .navigationBarTitle("Choose")
  }
}


Replies

Have you found the solution to this? I am having a similar issue where even if I hide the NavigationLink inside .background() it is still visible in the background.

I'm having the same issue where an empty button shows. A workaround I found is to set the opacity to 0 and put the NavigationLink inside a ZStack as if it was inside a VStack it will still take space from the screen. Not sure how reliable this is but I'll test for a few days and see how it holds up!

if loginSucceeded {
     
      NavigationLink(destination: DashboardView(), isActive: $loginSucceeded) {
         
        EmptyView()
         
      }
}

Use one extra if check.