Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mliberatore opened this issue Nov 8, 2016 · 0 comments

Comments

@mliberatore
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant