'NavigationLink is grayed out and does not perform any action [duplicate]

import SwiftUI

struct ContentView: View {    
    var body: some View {
        NavigationLink(destination: DetailView()) {
            Text("Show Details")
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Detailed")
    }
}

This code gives me a gray text (or button) saying 'Show Details' which is not touchable and does not perform the intended action (navigating to DetailView). Was there a change in the API or is it a bug?

I am using the newest versions of Xcode (Xcode 11 Beta 6 and macOS Catalina 10.15 Beta 6)



Solution 1:[1]

Your ContentView should have a NavigationView for NavigationLink to work, and be enclosed in some 'element', here a VStack

struct ContentView: View {    
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: DetailView()) {
                     Text("Show Details")
                }
            }
        }
    }
}

Hope this helps!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fa65