Search code examples
swiftxcodeswiftuiswiftui-navigationlink

XCode IOS How to get rid of the back button on home screen?


I have a project with NavigationLink that leads a login screen into a main menu which is intended, but there is a back button that leads back to the login screen which I want to get rid of. How would I do so?


Solution

  • Under the view that you are presenting in the main menu, for instance:

    var body: some View {
        MyView()
            .navigationBarBackButtonHidden()
    }
    

    if you have a more complicated view, you can also put it under the layout container, like:

    var body: some View {
        HStack {
            // Your views
        }
        .navigationBarBackButtonHidden()
    }
    

    Your back button should be gone then.