GMRouter 0.1.1

GMRouter 0.1.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年3月

Gemini Wen 维护。



GMRouter 0.1.1

一个 URL 路由器,使用正则表达式解析 iOS 中的 URL。灵感来自 HHRouter

使用方法

热身

将 URL 模式映射到代码块。

GMRouter *router = [GMRouter shared];
GMRouterBlock block = ^(NSDictionary *params) {
    NSLog(@"%@", params[@"uid"]);
    NSLog(@"%@", params[@"pid"]);
};


[router map:@"/gemini/[uid]/[pid]" toBlock:block];

我们接下来得到什么

当请求 URL 时获取代码块和参数

GMRouterBlock newBlock = [router matchBlock:@"/gemini/123/23423?hello=world"];
newBlock(nil);

我们在代码块中将获得这些参数。

控制器如何

GMRouter *router = [GMRouter shared];
[router map:@"/q/[questionId]" toControllerClass:[UIViewController class]];
UIViewController *controller = [router matchViewController:@"/q/1000010000?__ea=111"];
XCTAssertEqualObjects(controller.params[@"questionId"], @"1000010000");