Created
October 18, 2022 12:19
-
-
Save ra9r/77cdb36cbc048f13b5b1dbbb062910f8 to your computer and use it in GitHub Desktop.
Programmatic navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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