navigationDestination for NavigationStack doesn’t work in iOS 16 Beta 4 and Xcode 14

This simple test code works fine in iOS 16 Beta 3:

struct ContentView: View {

    enum Route: Hashable {

        case one

        case two

    }



    var body: some View {

        NavigationSplitView {

            NavigationLink("Target One", value: Route.one)

            NavigationLink("Target Two", value: Route.two)

        } detail: {

            NavigationStack {

                Text("Home")

            }

            .navigationDestination(for: Route.self) { route in

                switch route {

                case .one:

                    Text("Target for Route One")

                case .two:

                    Text("Target for Route Two")

                }

            }

        }

    }

}

But in Beta 4 and Xcode 14 Beta 4 I got this error if I click on a NavigationLink:

A NavigationLink is presenting a value of type “Route” but there is no matching navigation destination visible from the location of the link. The link cannot be activated.

Is there something wrong with this code or is it a bug in beta 4? Anyone have ideas how to fix this?

Post not yet marked as solved Up vote post of netspy Down vote post of netspy
1.8k views
  • I ran into the same problem: beta 4 broke navigationDestination attached to a navigationStack in the detailsection of a navigationSplitview. Worked fine in beta 3...

Add a Comment

Replies

I ran into the same issue. I eventually discovered that it's caused by attaching the navigationDestination directly to the navigationStack. If you put it on a view within the NavigationStack it works.

I faced similar issue -

  1. make sure you are not using NavigationStack{} twice for a view.
  2. make sure to have NavigationDestination in a view hierarchy which is wrapped in NavigationStack. I had TabView and multiple views. Mistakenly I was using NavigationStack twice First I was wrapping tabview inside navigationStack and Second inside one of the views in tabview. hope it helps.