How to get an unownedRouter for RedirectionRouter?
kevinrenskers opened this issue · 2 comments
kevinrenskers commented
This is the example in the project readme:
class ParentCoordinator: NavigationCoordinator<ParentRoute> {
/* ... */
override func prepareTransition(for route: ParentRoute) -> NavigationTransition {
switch route {
/* ... */
case .child:
let childCoordinator = ChildCoordinator(parent: unownedRouter)
return .push(childCoordinator)
}
}
}
class ChildCoordinator: RedirectionRouter<ParentRoute, ChildRoute> {
init(parent: UnownedRouter<ParentRoute>) {
let viewController = UIViewController()
// this viewController is used when performing transitions with the Subcoordinator directly.
super.init(viewController: viewController, parent: parent, map: nil)
}
/* ... */
override func mapToParentRoute(for route: ChildRoute) -> ParentRoute {
// you can map your ChildRoute enum to ParentRoute cases here that will get triggered on the parent router.
}
}
But what do you do when viewController
needs be passed an UnownedRouter<ChildRoute>
so it can trigger routes? RedirectionRouter
doesn't have an unownedRouter
like actual coordinators do.
pauljohanneskraft commented
Hey @kevinrenskers,
UnownedRouter is actually a typealias for UnownedErased<StrongRouter>, so you should actually be able to do the following:
extension RedirectionRouter {
var unownedRouter: UnownedRouter<RouteType> {
UnownedRouter(self) { $0.strongRouter }
}
}
Let me know, if this helps - it would probably be a nice addition for the framework as well!
pauljohanneskraft commented
I'm closing this due to inactivity and a given solution that should work as expected - if you have further questions or the given solution does not work, feel free to add further comments or open additional issues.