Nested NavigationLinks not working properly in latest SwiftUI

Nested NavigationLinks are not working properly in latest 13.0 Beta (13A5155e). If you navigate to a nested NavLink, then return one level, NavigationLink Views turn gray if touched but do not go to the destination. See attached code.


struct ContentView: View {
  var body: some View {
    NavigationView {
      List(1..<100) { row in
        NavigationLink(destination: InnerListView()) {
          Text("Row \(row)")
        }
      }
      .navigationTitle("Outer List")
    }
  }
}

struct InnerListView: View {
  var body: some View {
    List(1..<100) { row in
      NavigationLink(destination: Text("Details for row \(row)")) {
        Text("Row \(row)")
      }
      .navigationTitle("Inner List")
    }
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}
Answered by tinonster in 680982022

I encounter the same problem and try to find where is wrong, then I remember a few days ago I have implemented this requirement and it worked, so I compare the code I have written and realize I need to add a modifier .isDetailLink(false) after every NavigationLink that is not linked to a final detail view. It works fine for me, hope this can help you.

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List(1..<100) { row in
                NavigationLink(destination: InnerListView()) {
                    Text("Row \(row)")
                }
                .isDetailLink(false)
            }
            .navigationTitle("Outer List")
        }
    }
}

struct InnerListView: View {
    var body: some View {
        List(1..<100) { row in
            NavigationLink(destination: Text("Details for row \(row)")) {
                Text("Row \(row)")
            }
            .isDetailLink(false)
            .navigationTitle("Inner List")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

seeing the same problem.

there seem to be a lot of things not working properly with NavigationView/NavigationLink judging by the number of unresolved questions and strange workarounds.

You can do this however, to let you select which list to go back to:

struct InnerListView: View {
    var body: some View {
        NavigationView {    // <--- here
            List(1..<100) { row in
                NavigationLink(destination: Text("Details for row \(row)")) {
                    Text("Row \(row)")
                }
                .navigationTitle("Inner List")
            }
        }
    }
}

yikes...

Accepted Answer

I encounter the same problem and try to find where is wrong, then I remember a few days ago I have implemented this requirement and it worked, so I compare the code I have written and realize I need to add a modifier .isDetailLink(false) after every NavigationLink that is not linked to a final detail view. It works fine for me, hope this can help you.

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List(1..<100) { row in
                NavigationLink(destination: InnerListView()) {
                    Text("Row \(row)")
                }
                .isDetailLink(false)
            }
            .navigationTitle("Outer List")
        }
    }
}

struct InnerListView: View {
    var body: some View {
        List(1..<100) { row in
            NavigationLink(destination: Text("Details for row \(row)")) {
                Text("Row \(row)")
            }
            .isDetailLink(false)
            .navigationTitle("Inner List")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Nested NavigationLinks not working properly in latest SwiftUI
 
 
Q