Need help with XRouter?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

410 Stars 20 Forks MIT License 75 Commits 1 Opened issues


Navigate anywhere in just one line.

Services available


Need anything else?

Contributors list


Build Status CodeCov Badge Codacy Badge
Docs Badge Version License Language


Decouple your code with abstract routes, add powerful deep-linking and ditch the boilerplate.

Get Started

Define App Routes

Create an

file with your abstract routes in it.
enum AppRoute: RouteType {
    case newsfeed
    case login
    case signup
    case profile(userID: Int)

Create a Router

Extend a concrete Router instance to resolve your view controllers. ```swift class Router: XRouter {

override func prepareDestination(for route: AppRoute) throws -> UIViewController {
    switch route {
    case .newsfeed: return

case .login:
    return LoginFlowCoordinator().start()

case .signup:
    return SignupFlowCoordinator().start()

case let .profile(userID):
    guard let profile = profilesRepository.fetch(userId) else {
        throw NotFoundError("Could not find profile with that ID.")

    return UserProfileViewController().configured(with: profile)


} ```


// Navigate directly to a route
router.navigate(to: .profile(3355))

Advanced Usage


XRouter also supports the RxSwift framework out of the box. Bindings exist for

, which returns a
, and
, which returns a
router.rx.navigate(to: .loginFlow) // -> Completable
router.rx.openURL(url) // -> Single

Deep Link Support

XRouter provides support for deep links and universal links.

You only need to do one thing to add URL support for your routes. Implement the static method

: ```swift enum AppRoute: RouteType {
static func registerURLs() -> URLMatcherGroup? {
    return .group {
        $"/products") { .allProducts }
        $"/user/*/logout") { .logout }
        $"/products/{cat}/view") { try .products(category: $0.path("cat")) }

    $"/user/{id}/profile") {
        try .viewProfile(withID: $0.path("id"), parameters: $0.query)


} ```

Then you can call the

continue(_ userActivity:)
methods, e.g. from in your AppDelegate: ```swift extension AppDelegate {
/// Handle deep links.
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    return router.openURL(url, animated: false)

/// Handle universal links. func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { return router.continue(userActivity) }

} ```

You can even define more advanced URL routing. For example, these rules could be used to match:

  • customScheme://myApp/qr-code?code=abcdef...
enum AppRoute: RouteType {

static func registerURLs() -&gt; URLMatcherGroup<approute>? {
    return .init(matchers: [
        .host("") {
            $"/login") { .login }
            $"/signup") { .signup }
        .scheme("customScheme") {
            $"/qr-code") { .openQRCode($0.query("code")) }
        .group {
            $"/products") { .allProducts }
            $"/user/*/logout") { .logout }


Handling errors

If you handle all navigation errors in the same way, you can override the

class Router: XRouter {

override func received(unhandledError error: Error) {
    log.error("Oh no! An error occured: \(error)")


Or you can set a custom completion handler for some individual navigation action:

router.navigate(to: .profilePage(withID: 24)) { (optionalError) in
    if let error = optionalError {
        print("Oh no, we couldn't go here because there was an error!")

Custom Transitions

Here is an example using the popular Hero Transitions library.

Define your custom transitions: ```swift /// Hero cross fade transition let heroCrossFade = RouteTransition { (source, dest, animated, completion) in source.hero.isEnabled = true dest.hero.isEnabled = true dest.hero.modalAnimationType = .fade

  // Present the hero animation
  source.present(dest, animated: animated) {

} ```

And set the transition to your custom transition in your Router: ```swift override func transition(for route: AppRoute) -> RouteTransition { if case Route.profile = route { return heroCrossFade }

    return .automatic
## Documentation

Complete documentation is available here and is generated using Jazzy.


To run the example project, clone the repo, and run it in Xcode 10.



Swift Package Manager

XRouter is available through Swift Package Manager from version 2.0.1 onwards.


XRouter is available through CocoaPods. To install it, simply add the following line to your Podfile:

```ruby pod 'XRouter'


Reece Como, [email protected]


XRouter is available under the MIT license. See the LICENSE file for more info.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.