Skip to content

Deep Links to Routes with a Single Path Component Break with Trailing Slash #113

@mliberatore

Description

@mliberatore

Using 1.2.1, I’m noticing an issue with routes that consist of a single path component failing to be handled when a trailing slash is included in the URL. This issue is not present when there is more than one path component in the registered route.

Example

In Info.plist, I have the following scheme, test, set up so that my test app opens from Mobile Safari for URLs that begin with test://.

screen shot 2016-11-08 at 4 16 51 pm

This is the entirety of AppDelegate.m in an otherwise empty test project, in which I demonstrate the issue:

#import "AppDelegate.h"
#import <DeepLinkKit/DeepLinkKit.h>

@interface AppDelegate ()

@property (nonatomic) DPLDeepLinkRouter *router;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.router = [[DPLDeepLinkRouter alloc] init];
    
    self.router[@"search"] = ^(DPLDeepLink *link) {
        // Called for `test://search`
        // Not called for `test://search/` <-- THE ISSUE
        NSLog(@"Handled Search Link");
    };
    
    self.router[@"settings/about"] = ^(DPLDeepLink *link) {
        // Called for `test://settings/about`
        // Called for `test://settings/about/`
        NSLog(@"Handled settings/about Link");
    };
    
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [self.router handleURL:url withCompletion:NULL];
}

@end

In summary, the issue shown in this example is that when attempting to open test://search/ in Mobile Safari the handler that logs the message "Handled Search Link" is not called.

Workaround

There is a workaround to the issue, and that is to specify /? to the end of the registered route to allow for an optional trailing slash. In the example above, that’d change the registration of search to be:

self.router[@"search/?"] = ^(DPLDeepLink *link) {
    // Called for `test://search`
    // Called for `test://search/`
    NSLog(@"Handled Search Link");
};

However, this is not ideal as it requires treating routes with different numbers of components differently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions