Skip to content

Instantly share code, notes, and snippets.

@ra9r
Created October 18, 2022 12:19
Show Gist options
  • Save ra9r/77cdb36cbc048f13b5b1dbbb062910f8 to your computer and use it in GitHub Desktop.
Save ra9r/77cdb36cbc048f13b5b1dbbb062910f8 to your computer and use it in GitHub Desktop.
Programmatic navigation
struct ShopContainerView: View {
@StateObject private var store = Store()
@State private var path: [Product] = []
var body: some View {
NavigationStack(path: $path) {
List(store.products) { product in
NavigationLink(product.title, value: product)
}
.task { await store.fetch() }
.navigationDestination(for: Product.self) { product in
ProductView(product: product)
.toolbar {
Button("Show similar") {
path.append(product.similar[0])
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment