 
 extension XCTableViewDataSource {
     public var router: Router {
-        guard let router = tableView?.viewController?.router else {
+        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(viewController: UIViewController())
+            return Router(navigationController: nil)
         }
 
         return router

}

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 XCCollectionViewDataSource {
    public var router: Router {
        guard let collectionView = collectionView else {
            return Router(navigationController: nil)
        }

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

        return router
