针对swift的页面路由 路由的理解
swift3+ and xcode8+
pod "ACRouter"
- 需要路由的控制器遵守协议
ACRouterable
, 并实现方法registerAction
.
class CustomViewController: UIViewController, ACRouterable {
static func registerAction(info: [String : AnyObject]) -> AnyObject {
let newInstance = LoginViewController()
if let title = info["username"] as? String {
newInstance.title = title
}
return newInstance
}
}
- 注册路由
ACRouter.addRouter("AA://bb/cc/:p1", classString: "CustomViewController")
- 通过URL打开控制器
ACRouter.openURL("AA://bb/cc/content?value1=testInfo")
- 快速添加路由映射关系
let registerDict = ["AA://bb/cc/:p1" : "CustomViewControllerOne", "AA://ee/ff" : "CustomViewControllerTwo"]
ACRouter.addRouter(registerDict)
- 快速生成跳转URL
//自动将参数params和jumptype嵌入到注册的URL当中
ACRouter.generate(_ patternString: params: jumpType: )
- 检查跳转URL
canOpenURL(_ urlString: )
- 移除路由
removeRouter(_ patternString: )
- 添加路由, 自己配置优先级和HandleBlock
//注册的路由将按优先级逆序排序
ACRouter.addRouter(patternString: priority: handle: )
- 请求URL
//返回匹配的路由与所有解析出来的参数
ACRouter.requestURL(urlString: userInfo: )
-
AddInterceptor
for router -
Add Test for router -
AddopenURL
failed action - Add
relocation
-
openURL
not only support Viewcontroller jumping
JLRoutes 、 MGJRouter 、 ARoutes
欢迎提出你们宝贵的意见, 你们的star与issue是我前进的动力
ACRouter is available under the MIT license. See the LICENSE file for more info.