How dimillian/approuter works
Project type and purpose
• This is an open-source Swift Package (“AppRouter”) that provides a generic, reusable navigation router for SwiftUI apps.
• It exposes two main router types (SimpleRouter and Router) plus URL‐based deep linking, sheet presentation, and tab‐based navigation support.
File structure
• Top level:
• Sources/AppRouter – the core library code
• Examples – sample SwiftUI apps showing usage
• Tests – unit tests for SimpleRouter and Router
• Inside Sources/AppRouter:
• Protocols.swift – DestinationType, SheetType, TabType
• Router.swift / SimpleRouter.swift – the two router implementations
• URLNavigationHelper.swift – deep‐link parsing & dispatch
• Extensions.swift – helpers (e.g. URL builders)
Key README insights
• Two router classes annotated @Observable and @MainActor
• Generic protocols to allow apps to define their own Destination, Sheet, Tab enums
• SwiftUI integration via NavigationStack(path:), TabView(selection:), .sheet(item:) and .onOpenURL
a. Main components
• Protocols module (DestinationType, SheetType, TabType)
• Core Routers
• SimpleRouter<Destination,Sheet>
• Router<Tab,Destination,Sheet>
• URLNavigationHelper (parses URLs into Destination instances)
• Extensions (URL deep-link helper, type aliases)
• SwiftUI Integration layer—NavigationStack, TabView, .sheet, .onOpenURL
• App code (your Destination/Sheet/Tab implementations & Views)
b. Relationships & interactions
• App defines Destination/Sheet/Tab enums → conforms to Protocols → feeds into Routers
• Routers expose @Published path & presentedSheet → bound to SwiftUI views
• URLNavigationHelper parses incoming URLs → invokes router.navigate(to:)
• Router updates path/sheet → SwiftUI renders navigationDestination or .sheet
• In tab-based case, Router.selectedTab ↔ TabView(selection:)
c. Architectural patterns & design principles
• Generics + Protocols for high flexibility and type safety
• Reactive state management via @Observable and @MainActor for UI safety
• Separation of concerns: core routing logic decoupled from SwiftUI views
• Extensibility points via Protocols (apps plug in custom Destination/Sheet/Tab)
d. Relevant technologies
• Swift Package Manager (Package.swift)
• Swift 5.9, @Observable, @MainActor
• SwiftUI: NavigationStack, TabView, .sheet(item:), .onOpenURL