TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2015 |
Maintained by liaojinxing.
URL Router for any object in iOS.
There are many open source routers, why make this wheel again?
Almost other routers are limited to controller or block, while LJURLRouter can route any object.
In some cases, use an url to represent an object when communicating with server, will reduce network traffic.
Just openURL to navigate a controller, but not import the controller header file and call pushViewController...
Other than navigation inside app, you can handle navigation easily for url schema, deep link, 3D Touch, spotlight search.
Register url formats and the matching class.
[[LJURLRouter sharedRouter] registerURL:YOUR_URL_FORMAT forClass:[YOUR_CLASS_NAME class]];
for example:
[[LJURLRouter sharedRouter] registerURL:@"/profile/:profile_id" forClass:[ProfileViewController class]];
Get matching object instance from URL. Params will be parsed automatically
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:YOUR_URL_HERE];
for example:
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:@"/profile/123?param1=hello¶m2=world"];
LJURLRouter also provides a category of UIViewController for convienient use.
[controller openURL:@"/profile/123?param1=hello¶m2=world"]
Default schema is also supported.
UIViewController category supports multi route types, including push in navigation controller and present.
For more details, please check the demo project and unit tests.
Grab the source file into your project.
Or use cocoapods. Here is an example of your podfile:
pod 'LJURLRouter'
LJURLRouter is available under the MIT license. See the LICENSE file for more info.
开源社区已经有很多不错的router,但并不满足需求。
很多实现都是局限于controller和block,LJURLRouter主要是用于对象的映射,支持任意class.
与server通信时,很多情况下无法直接传递对象,或者为了节省流量,可以通过定义一套url routing协议来进行通信。例如使用/user/123 代表123这个user,而无需返回一个user对象。
处理端内页面的跳转时,可以直接openURL,而无需import controller,再pushViewController
可以轻松地处理推送通知, url schema, deep link, 3D Touch, spotlight search 等跳转
[[LJURLRouter sharedRouter] registerURL:YOUR_URL_FORMAT forClass:[YOUR_CLASS_NAME class]];
例子:
[[LJURLRouter sharedRouter] registerURL:@"/profile/:profile_id" forClass:[ProfileViewController class]];
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:YOUR_URL_HERE];
例子:
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:@"/profile/123?param1=hello¶m2=world"];
提供了一个UIViewController的category,可以方便地进行controller之间的跳转
[controller openURL:@"/profile/123?param1=hello¶m2=world"]
LJURLRouter支持默认schema
更详细的使用方法,可以看demo和单元测试
可以直接把源码放到你的工程里,或者使用CocoaPods:
pod 'LJURLRouter'
MIT