As you saw in Navigation, we use Events to send messages upwards in the hierarchy, but with Routing we can define our navigation state in a top to bottom fashion, setting the Route of the Coordinators
downwards in the hierarchy.
For that, your Coordinator
only needs to conform to the HasRoutes
protocol, implement an enum with the possible Routes and the goTo(_ route: Route) method, like the following example
extension TeamsCoordinator: HasRoutes {
enum Route: Equatable {
case list
case team(_ team: Team)
}
func goTo(_ route: Route) {
switch route {
case .list:
self.showListScreen()
case .team(let team):
self.showTeamScreen(team)
self.activeRoute = route
}
private func showListScreen() {
let coordinator = getCached(TeamsListCoordinator.self) ?? TeamsListCoordinator()
self.root(coordinator)
}
private func showTeamScreen(_ team: Team) {
let coordinator = getCached(TeamsDetailsCoordinator.self) ?? TeamsDetailsCoordinator()
coordinator.team = team
self.show(coordinator, sender: self)
}
}
Found errors? Think you can improve this documentation? Simply click the Edit link at the top of the page, and then the icon on Github to make your changes.