# Navigation

Of course our app won’t have just a single screen — we typically have multiple screens that we want to navigate to and from. In SwiftUI, navigation between views is very simple and similar to that of UIKit.

### Creating a Navigation Stack

For iOS 16 and later, we use a `NavigationStack` which is a view that displays a root view and enables us to present additional views **over** the root view. This is similar to a `UINavigationController` in UIKit.

```swift
NavigationStack {
    // Place views here
}
```

If we are using iOS 15 or earlier, we can also use a `NavigationView` which serves the same purpose.

### Navigation Modifiers

To modify the navigation, we can use modifiers. However, the modifier must be placed in the view nested inside of the `NavigationStack`, not on the `NavigationStack` itself.

For example, if we wanted to add a title to the navigation bar, we can use the `.navigationTitle` modifier. Note that we are using the modifier on the `Text` view which is inside of the `NavigationStack`.

```swift
NavigationStack {
    Text("AppDev")
        .navigationTitle("Some Title Here")
}
```

### Pushing a View

To push a view, we use a `NavigationLink`, which is a view that controls a navigation presentation. This is similar to pushing a ViewController in UIKit. There are many different ways to use this; however, the preferred and conventional way to use it is with the trailing closure syntax:

```swift
NavigationStack {
    NavigationLink {
        // View that is being pushed (the destination)
    } label: {
        // View that is being tapped on (such as a Text)
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ios-course.cornellappdev.com/resources/textbook/swiftui/navigation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
