joeldev /JLRoutes

URL routing library for iOS with a simple block-based API

★ 5,702⑂ 686👁 132⑃ 54● 73▤ 20
Objective-CBSD-3-ClauseCreated 2013-02-10
下载:JLRoutes 2.1.1JLRoutes-2.1.1 ↓2.1.12021-08-10
+0
日增长
5,702
stars
686
forks
132
watchers
54
prs
73
issues
20
releases

README

JLRoutes
========







 What is it? 
JLRoutes is a URL routing library with a simple block-based API. It is designed to make it very easy to handle complex URL schemes in your application with minimal code.

 Installation 
JLRoutes is available for installation using CocoaPods or Carthage (add github "joeldev/JLRoutes" to your Cartfile).

 Requirements 
JLRoutes 2.x require iOS 8.0+ or macOS 10.10+. If you need to support iOS 7 or macOS 10.9, please use version 1.6.4 (which is the last 1.x release).

 Documentation 
Documentation is available here.

 Getting Started 

Configure your URL schemes in Info.plist.

objc
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
  JLRoutes routes = [JLRoutes globalRoutes];

  [routes addRoute:@"/user/view/:userID" handler:^BOOL(NSDictionary parameters) {
    NSString userID = parameters[@"userID"]; // defined in the route by specifying ":userID"

    // present UI for viewing user with ID 'userID'

    return YES; // return YES to say we have handled the route
  }];

  return YES;
}

- (BOOL)application:(UIApplication )app openURL:(NSURL )url options:(NSDictionary )options
{
  return [JLRoutes routeURL:url];
}


Routes can also be registered with subscripting syntax:
objc
JLRoutes.globalRoutes[@"/user/view/:userID"] = ^BOOL(NSDictionary parameters) {
  // ...
};


After adding a route for /user/view/:userID, the following call will cause the handler block to be called with a dictionary containing @"userID": @"joeldev":
objc
NSURL viewUserURL = [NSURL URLWithString:@"myapp://user/view/joeldev"];
[JLRoutes routeURL:viewUserURL];


 The Parameters Dictionary 

The parameters dictionary always contains at least the following three keys:
json
{
  "JLRouteURL":  "(the NSURL that caused this block to be fired)",
  "JLRoutePattern": "(the actual route pattern string)",
  "JLRouteScheme": "(the route scheme, defaults to JLRoutesGlobalRoutesScheme)"
}


The JLRouteScheme key refers to the scheme that the matched route lives in. Read more about schemes.

See JLRoutes.h for the list of constants.

 Handler Block Chaining 

The handler block is expected to return a boolean for if it has handled the route or not. If the block returns NO, JLRoutes will behave as if that route is not a match and it will continue looking for a match. A route is considered to be a match if the pattern string matches and the block returns YES.

It is also important to note that if you pass nil for the handler block, an internal handler block will be created that simply returns YES.

 Global Configuration 

There are multiple global configuration options available to help customize JLRoutes behavior for a particular use-case. All options only take affect for the next operation.

objc
/// Configures verbose logging. Defaults to NO.
+ (void)setVerboseLoggingEnabled:(BOOL)loggingEnabled;

/// Configures if '+' should be replaced with spaces in parsed values. Defaults to YES.
+ (void)setShou

Top issues

Latest release

JLRoutes 2.1.1 2.1.1 2021-08-10
Support for Swift Package Manager

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON