BRouter 0.1.0

BRouter 0.1.0

mike 维护。



BRouter 0.1.0

  • 作者:
  • owliVendy

BRouter

概述

一个用于组件间通信的 Router,开发思路来自 MGJRouter。感谢蘑菇街开源的代码。此库提供以下功能:

  • 可以自由注册 URL 和相应的响应方法
  • 使用协议的方式,简化控制器间的跳转和注册

用法

自定义注册

///自定义,方式注册
BRouter.register(url: "appscheme://user/getUserInfo") { (query, extend, callback) in
    //打印参数
    print(query)
    print(extend)
    //query, extend, callback
    //模拟网络请求
    DispatchQueue.global().async {
        sleep(2)
        DispatchQueue.main.async {
            callback?(["result":"success"])
        }
    }
}

///处理 url
BRouter.handle(url: "appscheme://user/getUserInfo?userId=121", extened: ["Image":1]) { (paramters) in
    ///回调结果参数
    print("请求结果 \(paramters)")
}

页面注册

///注册页面跳转,跳转的页面YourViewController 需要实现PageRouterable 用来接收参数
BRouter.map(url: "appscheme://item/detail", page: YourViewController.self)

///拿到配置的url, 跳转到匹配的页面
let url = "appscheme://item/detail?id=1&name=小飞"
BRouter.open(url: url, from: self.navigationController)

要求

  • Xcode 10.2+
  • Swift 5.0+(适用于最新版本)

安装

支持Cocoapod,但尚未发布到Cocoapods,可以通过私有库方式集成。

BRouter 可通过 CocoaPods 获取。要安装,只需将以下行添加到您的 Podfile 中

pod 'BRouter'

作者

owliVendy,[email protected]

许可证

BRouter 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。