Browse Questions
Answer:
NavigationStack (iOS 16+) replaces NavigationView and uses a path-based approach for programmatic navigation, making deep linking and state-driven navigation much cleaner.
Code Example:
struct AppView: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
HomeView()
.navigationDestination(for: Article.self) { article in
ArticleDetailView(article: article)
}
.navigationDestination(for: User.self) { user in
UserProfileView(user: user)
}
}
}
}
// Navigate programmatically
path.append(someArticle) // push
path.removeLast() // pop
path = NavigationPath() // pop to root