跳转至
Structure

NavigationLink

A view that controls a navigation presentation.

Declaration

struct NavigationLink<Label, Destination> : View where Label : View, Destination : View

Overview

Use NavigationLink to add a button that pushes a new view onto the navigation stack.

For example, the following presents BananasView when the link "I want bananas!" is pressed:

struct ExampleView: View {
    struct BananasView: View {
        var body: some View {
            Text("Bananas")
                .navigationTitle("🍌🍌")
        }
    }

    var body: some View {
        NavigationView {
            NavigationLink(destination: BananasView()) {
                Text("I want bananas!")
            }
        }
    }
}
A gif that shows a view displaying a navigation link with a text button that reads "I want bananas!"; once the button is clicked, another view with a navigation title reading "🍌🍌" and text reading "Bananas" slides left over the main view.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Type Alias

Body The type of view representing the body of this view.


Instance Property

body The content and behavior of the view.


Instance Method

isDetailLink(_:) Sets whether or not the NavigationLink should present its destination as the "detail" component of the containing NavigationView.


Initializer

init(_:destination:) Creates an instance that presents destination, with a Text label generated from a title string.

init(_:destination:) Creates an instance that presents destination, with a Text label generated from a title string.

init(_:destination:isActive:) Creates an instance that presents destination when active, with a Text label generated from a title string.

init(_:destination:isActive:) Creates an instance that presents destination when active, with a Text label generated from a title string.

init(_:destination:tag:selection:) Creates an instance that presents destination when selection is set to tag, with a Text label generated from a title string.

init(_:destination:tag:selection:) Creates an instance that presents destination when selection is set to tag, with a Text label generated from a title string.

init(destination:isActive:label:) Creates an instance that presents destination when active.

init(destination:label:) Creates an instance that presents destination.

init(destination:tag:selection:label:) Creates an instance that presents destination when selection is set to tag.