Latest 1.0
Homepage https://github.com/wanggang316/RouterMan
License MIT
Platforms ios 10.0
Authors

RouterMan GitHub license Cocoapods

RouterMan is a protocol-oriented url router, base on regular expressions. RouterMan is simple and extensible.

Requirements

  • iOS 10 or later
  • Swift 4

Features

  • [x] Regular expressions support
  • [x] Storyboard controller support´╝îyou can open a storyboard based controller easily
  • [x] Mutable source urls to a target behavior
  • [x] Mutable transitions support

Installation with CocoaPods

pod 'RouterMan'

Installation with Carthage

github "wanggang316/RouterMan"

Useage

It’s simple to use RouterMan, implement RoutableType based protocol for your controller or other types, then registe it to RouteMan, done.

RoutableType is routable base protocol, it derivative three protocols

  • RoutableControllerType
  • RoutableStoryboardControllerType
  • RoutableActionType

Config RoutableType

  • RoutableControllerType
class CityViewController: UIViewController: RoutableControllerType {

    static var patterns: [String] {
        return ["abc://page/cities/\d+\?name=\w+"]
    }

    required convenience init(_ url: URLConvertible) {
        self.init()
        let params = url.urlValue?.queryParameters
        let title = params?["name"]
        self.title = title
    }
}
  • RoutableStoryboardControllerType
extension StoryViewController: RoutableStoryboardControllerType {

    static var patterns: [String] {
        return ["abc://page/stories/\d+\?name=\S+",
                "http://www.xxx.com/stories/\d+\?name=\w+"]
    }

    static var storyboardName: String {
        return "Main"
    }

    static var identifier: String {
        return "StoryViewController"
    }

    func initViewController(_ url: URLConvertible) {
        self.storyId = url.urlValue?.pathComponents.last
        self.storyName = url.urlValue?.queryParameters["name"]
    }
}
  • RoutableActionType
class AlertActionRouter: RoutableActionType {
    static func handle(_ url: URLConvertible) -> Bool {
        let title = url.urlValue?.queryParameters["title"]
        let message = url.urlValue?.queryParameters["message"]

        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Yes", style: .cancel, handler: nil))

        let appdelegate = UIApplication.shared.delegate as? AppDelegate
        appdelegate?.window?.rootViewController?.present(alert, animated: true, completion: nil)

        return true
    }

    static var patterns: [String] {
        return ["abc://alert\?title=\w+&message=\w+"]
    }
}

Registe

Router.default.registe(CityViewController.self)
Router.default.registe(StoryViewController.self)
Router.default.registe(AlertActionRouter.self)

Handle

try? Router.default.handle(url)

License

RouterMan is released under the MIT license.

Latest podspec

{
    "name": "RouterMan",
    "version": "1.0",
    "summary": "A lightweight, extensible Swift URL Router.",
    "homepage": "https://github.com/wanggang316/RouterMan",
    "license": "MIT",
    "authors": {
        "gump": "[email protected]"
    },
    "social_media_url": "https://twitter.com/wgang316",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/wanggang316/RouterMan.git",
        "tag": "1.0"
    },
    "source_files": "RouterMan/RouterMan/*.swift"
}

Pin It on Pinterest

Share This