I've encountered a strange glitch with NavigationStack when mixing the old-style NavigationLink with the new .navigationDestination style ones. While this example is trivial and easily fixed here, in my larger project, I can't convert everything at once. As a result, there are instances where both styles are used within the same NavigationStack.
The following preview demonstrates the issue: You'll tap 'One', then 'Two', expecting a transition to 'Three'. However, instead of 'Three', 'Two' reappears. This cycle continues indefinitely if 'Two' is repeatedly tapped.
When navigating back, the strange behaviour continues, and we see 'Three' appearing at each transition on the way back out.
Any ideas on this very peculiar bug?
#Preview {
NavigationStack {
NavigationLink("One") {
NavigationLink("Two", value: 1)
.navigationDestination(for: Int.self) { _ in
Text("Three")
}
}
}
}
This seems like a bug, a report to Apple is more appropriate than a workaround.
I was going to suggest a wrapper than can quickly convert the old
to
The behavior still exists. It seems like "Two" gets pushed over "Three" every time.
I added some
navigationTitleto visualize what was going on.You can notice that the
Backbutton switches to "Three` when clicking on Three but Two is shown in the content.Here is the code I used.