Trailing closure passed to parameter of type 'Visibility' that does not accept a closure

You cannot place a NavigationLink inside a Button action code.

You can use a NavigationLink in it’s own right though.

In order to see the Navigation Bar at the top and the “buttons’” you want to use to navigate, then you need to wrap the Text() View in a NavigationStack as per the code below.
Also if you want a title to appear at the top in the middle on the navigation bar then you should use the modifier .navigationTitle("Welcome") rather than using a ToolBarItem as a defacto title :

struct HomeView: View {

    var body: some View {
        NavigationStack {
            Text("Home")
                .toolbar {
                    ToolbarItem(placement: .navigationBarLeading) {
                        NavigationLink(destination: AccountView()) {
                            Image(systemName: "gearshape")
                        }
                    }

//                    ToolbarItem(placement: .principal) { Text("Welcome").font(.title) }

                    ToolbarItem(placement: .navigationBarTrailing) {
                        NavigationLink(destination: AccountView()) {
                            Image(systemName: "person.circle")
                        }
                    }
                }
                .navigationTitle("Welcome")
                .navigationBarTitleDisplayMode(.inline)
        }
    }
}
1 Like