Router.swift 872 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // Router.swift
  3. // SUIExamples
  4. //
  5. // Created by Pavel Yurchenko on 27.11.2024.
  6. //
  7. import Foundation
  8. import SwiftUI
  9. final class Router: ObservableObject {
  10. @Published
  11. var path = NavigationPath()
  12. func push(_ route: Route) {
  13. path.append(route)
  14. }
  15. func pop() {
  16. path.removeLast()
  17. }
  18. @ViewBuilder
  19. func buildDestination(_ route: Route) -> some View {
  20. switch route {
  21. case .main:
  22. MainBuilder().build(with: .init(onProducts: { [weak self] in
  23. self?.push(.products)
  24. }))
  25. case .products:
  26. ProductsBuilder().build(with: .init())
  27. case .product:
  28. MainBuilder().build(with: .init())
  29. case .cart:
  30. MainBuilder().build(with: .init())
  31. case .feedback:
  32. MainBuilder().build(with: .init())
  33. }
  34. }
  35. }