 }
 
 private struct RouteHandlerAssociatedKey {
-    static var viewController = "viewController"
+    static var navigationController = "navigationController"
 }
 
 extension RouteHandler {
     public var navigationController: UINavigationController? {
-        return viewController?.navigationController
+        return objc_getAssociatedObject(self, &RouteHandlerAssociatedKey.navigationController) as? UINavigationController
     }
 
-    fileprivate var viewController: UIViewController? {
-        get { return objc_getAssociatedObject(self, &RouteHandlerAssociatedKey.viewController) as? UIViewController }
-        set { objc_setAssociatedObject(self, &RouteHandlerAssociatedKey.viewController, newValue, .OBJC_ASSOCIATION_ASSIGN) }
+    fileprivate func setNavigationController(_ navigationController: UINavigationController?) {
+        objc_setAssociatedObject(self, &RouteHandlerAssociatedKey.navigationController, navigationController, .OBJC_ASSOCIATION_ASSIGN)
     }
 }
 

}

public class Router {
    private weak var viewController: UIViewController?

    fileprivate init(viewController: UIViewController) {
        self.viewController = viewController
    }

    public func configure<T: RouteHandler>(_ handler: T) -> T {
        var handler = handler
        handler.viewController = viewController
        return handler
    }
}

// MARK: Extensions

extension UIViewController {
    private struct AssociatedKey {
        static var router = "router"
    }

    public var router: Router {
        get {
            let router: Router

            if let existingRouter: Router = associatedObject(&AssociatedKey.router) {
                router = existingRouter
            } else {
                router = Router(viewController: self)
                self.router = router
            }

            return router


extension XCTableViewDataSource {
    public var router: Router {
        guard let tableView = tableView else {
            return Router(navigationController: nil)
        }

        guard let router = tableView.viewController?.router else {
            #if DEBUG
            if isDebuggerAttached {
                fatalError("Datasource doesn't have a view controller.")
            }
            #endif
            return Router(navigationController: nil)
        }

        return router
