@Reducer
struct NavigationDemo {
@Reducer
enum Path {
case screenA(ScreenA)
case screenB(ScreenB)
case screenC(ScreenC)
}
@ObservableState
struct State {
var path = StackState<Path.State>()
}
enum Action {
case path(StackActionOf<Path>)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
// Parent logic
}
.forEach(\.path, action: \.path)
}
}
struct NavigationDemoView: View {
@Bindable var store: StoreOf<NavigationDemo>
var body: some View {
NavigationStack(path: $store.scope(state: \.path, action: \.path)) {
Form {
NavigationLink(
"Go to Screen A",
state: NavigationDemo.Path.State.screenA(ScreenA.State())
)
NavigationLink(
"Go to Screen B",
state: NavigationDemo.Path.State.screenB(ScreenB.State())
)
}
.navigationTitle("Root")
} destination: { store in
switch store.case {
case .screenA(let store):
ScreenAView(store: store)
case .screenB(let store):
ScreenBView(store: store)
}
}
}
}