Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 2.64 KB

README.md

File metadata and controls

85 lines (60 loc) · 2.64 KB

HHRouter

Build Status Cocoapods

Yet another URL Router for iOS. Clean, Fast & Flexible. Inspired by ABRouter & Routable iOS.

Usage

Warm Up

Map URL patterns to viewController. Better in AppDelegate.

[[HHRouter shared] map:@"/user/:userId/" toControllerClass:[UserViewController class]];

Define a NSDictionary property named params in viewControllers. Better in your BaseViewController.

@interface UserViewController : UIViewController
@property (strong, nonatomic) NSDictionary *params;
@end

Exciting Time

Get viewController Instance from URL. Params will be automatic parsed.

UIViewController *viewController = [[HHRouter shared] match:@"/user/1/"];
XCTAssertEqualObjects([viewController class], [UserViewController class]);
XCTAssertEqualObjects(viewController.params[@"route"], @"/user/1/");
XCTAssertEqualObjects(viewController.params[@"userId"], @"1");

URL Query Params

URL Query Params is also supported, which will make things VERY flexible.

UIViewController *viewController = [[HHRouter shared] match:@"/user/1/?tabIndex=3"];
XCTAssertEqualObjects(viewController.params[@"tabIndex"], @"3");

One More Thing

If your app has defined some url schemes, HHRouter will know.

UIViewController *viewController = [[HHRouter shared] match:@"hhrouter://user/1/"];
XCTAssertEqualObjects([viewController class], [UserViewController class]);

Installation

pod 'HHRouter', '0.1'
#import <HHRouter/HHRouter.h>

If you're not able to use CocoaPods, please install HHRouter as a git submodule and add the files to your Xcode project.

Contact

Who use HHRouter?

If you're building your applications using HHRouter, please let me know! (add your application name & App Store link here and pull reuqest this README.

License

HHRouter is available under the MIT license.