TESTABLE CODE: public enum Destination: String, Codable, Hashable { case cookie = Cookie 🍪 case milk = Milk 🥛 } final class Router: ObservableObject { @Published var navPath = NavigationPath() func navigate(to destination: Destination) { navPath.append(destination) print(||| Router: add to navPath: (navPath.count)) } func navigateBack() { guard navPath.count > 0 else { return } navPath.removeLast() print(||| Router: remove from navPath: (navPath.count)) } func navigateToRoot() { guard navPath.count > 1 else { return } navPath.removeLast(navPath.count) } } struct RootView: View { @ObservedObject var router = Router() var body: some View { NavigationStack(path: $router.navPath) { List { Button(action: { router.navigate(to: .cookie) }, label: { Text(Destination.cookie.rawValue) }) Button(action: { router.navigate(to: .milk) }, label: { Text(Destination.milk.rawValue) }) } .navigationBarBackButtonHidden() .navigationDestination(for: Destination.self) { destination in let _ = pri
Topic:
UI Frameworks
SubTopic:
SwiftUI