Router doesn't hold any state, all values required for navigation are calculated on the fly based on UIViewController properties. It's fully compatible with existing project navigation system. You can easily mix router navigation command calls with performing segues or push/present/dismiss/etc. Therefore it can be painlesly added to any ongoing project.
- Simple navigation commands
- Navigate back to any controller with result
- Jump to any controller in navigation tree
- Super friendly to existing project navigation
- Can be painlessly added to ongoing project
- Architecture agnostic
- Lightweight
Provide access point to router (from view controller, for example):
extension UIViewController {
var router: Router {
return Router(window: UIApplication.shared.keyWindow, controller: self)
}
}let controller: UIViewController = ...
router.present(controller, animated: true, completion: { ... })router.push(controller, animated: true, completion: { ... })Note: completion closure is called immediately after the transition is completed.
router.back(
to: ViewController.self,
animated: true,
condition: { $0.id == 3 },
prepare: { controller in ... },
completion: { controller in ... }
)Provide condition in addition to target controller type, in case more than one controller of such type in back stack.
router.back(
animated: true,
prepare: { controller in ... },
completion: { controller in ... }
)router.backToWindowRoot(
animated: true,
prepare: { controller in ... },
completion: { controller in ... }
)Note: prepare closure is called before the transition begins. This closure can be used for returning some data to target controller.
router.replace(
with: controller,
animated: true,
completion: { ... }
)Note: replace even window root view controller.
router.setWindowRoot(
controller,
animated: true,
completion: { ... }
)Go to view controller wherever it positioned in navigation tree.
router.jump(
to: ViewController.self,
animated: true,
condition: { $0.id == 3 },
prepare: { controller in ... },
completion: { controller in ... }
)let controller = router.find(ViewController.self, condition: { $0.id == 3 })let controller = router.topControllerGet back navigation stack from current controller to window root:
let controllers = router.backStacklet controllers = router.topStackCustom container controller in navigation tree must adopt one of three container controller protocols.
If container contains just one child controller it must implement ContainerController protocol (example).
If container contains stack of child controllers, like UINavigationController, it must implement StackContainerController protocol (example).
If container contains child controller at one level, like UITabBarController or UIPageViewController, it must implement FlatContainerController protocol. See tab bar example or page controller example.
- Swift 4.2 +
- iOS 9.0 +
Route doesn't contain any external dependencies.
Add the following to Podfile:
pod 'Route'Download and drag files from Source folder into your Xcode project.
Route is distributed under the MIT License.


