1

I have a deeply nested View, and I want the back button to take the user all the way back up to one of the views which is quite near the root, instead of to the parent.

At the moment, in this View I have

   @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    var btnBack : some View { Button(action: {

          self.presentationMode.wrappedValue.dismiss()
          }) {
              HStack {
              Image("ic_back") // set image here
                  .aspectRatio(contentMode: .fit)
                  .foregroundColor(.white)
                  Text("Go home")
              }
          }
      }

and

  .navigationBarBackButtonHidden(true)
        .navigationBarItems(leading: btnBack)

How do I set the destination of the btnBack button to be the View named StatsView()? This is not the root view, but close to it.

Thank you

AAH
  • 99
  • 1
  • 10
  • What about opening sheet view(or fullscreencover) and use NavigationLink to somewhere? Then, you only need to put the dismiss function on the back button at the end. – Taeeun Kim Jun 26 '21 at 17:12

0 Answers0