Pick the fix
myapp://product/42 must open product 42 on top of Home. Which approach?
Hint 1 of 1
What drives NavigationStack?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Keep @State var path: [Route] = []; in .onOpenURL, set path = [.product(42)]; map .navigationDestination(for: Route.self)
Correct. Navigation is data, so a deep link is just a new path.
Why not the others?
- B NavigationLink(isActive:) with a Bool per screen. Deprecated since iOS 16, and it needs a flag per destination.
- C Present the product in a sheet. That changes the UX and doesn't build the back stack.
- D Find the UINavigationController and push a hosting controller. It fights SwiftUI's state and breaks easily.