Previewing the layout in a navigation view
Some views are designed to be presented in a navigation stack but are not themselves part of a navigation view. One solution to this problem would be to run the application and navigate to the view in question. However, previews provide a time-saving way to figure out how the view would be displayed without running the app.
In this recipe, we will create an app with a view that is part of the navigation stack and preview it in a navigation view.
Let's create a SwiftUI app called
How to do it…
We will add a
NavigationLink components to
ContentView that lead to a second view. The second view will not contain a navigation view but will be previewed in one. The steps are as follows: