Search code examples
swiftswiftuiswiftui-navigationlink

How made button works without navigation link (swiftui)


Button(action: {print("tapped")}) {
    HStack{
        NavigationLink(destination: HomePageView()){
            Text("Sign In")
            Spacer()
        }
    }
}

so I made the login screen and the button with navigation link and it works to homepage but in the homepage has a back button if I touch it, it back to the login screen again and how to solve it with navigation link or without navigation link


Solution

  • Assuming you want to hide the backbutton, you need to add the .navigationBarBackButtonHidden(true) modifier to the navigation link

    Button(action: {print("tapped")}){
                        HStack{
                            NavigationLink( destination: HomePageView().navigationBarBackButtonHidden(true)){
                            Text("Sign In")
                            Spacer()
                                }
                            }
                        }