shaffex

NavigationStack is a view that displays a root view and allows the user to navigate to subsequent views in a stack. It’s the recommended way to manage navigation in SwiftUI for apps targeting iOS 16 and later, replacing the deprecated NavigationView.

NavigationStack provides a more flexible and powerful way to handle navigation, including programmatic navigation and deep linking.

Parameters:

Example:

The example below shows a NavigationStack containing a List. The navigationTitle is set to “Navigation Stack”. A NavigationLink within the list allows the user to navigate to a detail view.

<body>
    <navigationstack>
        <list navigationTitle="Navigation Stack">
            <navigationlink destination="viewDetails">
                <text>Go to Details</text>
            </navigationlink>
        </list>
    </navigationstack>
    <text id="viewDetails">Details</text>
</body>

Screenshot

Inline Title Example:

This example demonstrates the use of navigationTitleDisplayMode="inline" to force the navigation title to always be displayed in the smaller, inline format.

<body>
    <navigationstack>
        <list navigationTitle="Navigation Stack" navigationTitleDisplayMode="inline">
            <navigationlink destination="viewDetails">
                <text>Go to Details</text>
            </navigationlink>
        </list>
    </navigationstack>
    <text id="viewDetails">Details</text>
</body>

Screenshot