ionic-team / ionic-plugin-deeplinks

Handle deeplinks into your Ionic/Cordova apps from Universal Links, App Links, and Custom URL schemes. For those using Ionic 2, there are some nice goodies that make life easier.
Other
332 stars 219 forks source link

Custom URL Scheme doesn't work without prefix (host) ? #48

Open fbrcdx opened 7 years ago

fbrcdx commented 7 years ago

Hi every one,

I have a problem with custom url schemes (deeplinks are OK). I can't make a defined route work without a "host" before...

Ex. : mycustomurlscheme://whateveryouwant/myregisteredroute/ OK mycustomurlscheme://myregisteredroute/ ERROR

Here is my AndroidManifest.xml params :

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="mycustomscheme" />
</intent-filter>

In my plaform's ready :

Deeplinks.route({
    '/myregisteredroute/': 'myroute'
}).subscribe((match) => {
    console.log('A deeplink did match');
}, (nomatch) => {
    console.log('A deeplink didn\'t match');
});

Then, when I call a link like : mycustomurlscheme://whateveryouwant/myregisteredroute/ The plugin see 'whateveryouwant' as a host and bring me 'myregisteredroute' as my path. In this case it works but this is not what I'm looking for.

But when I call a link like : mycustomurlscheme://myregisteredroute/ The plugin see 'myregisteredroute' as a host and bring me '/' as my path.

So the defined path (/myregisteredroute/') is never read if there's no character before.

Am I missing something in the plugin params ? In my point of view, if I'm using a CUSTOM scheme, the host shouldn't be taken into account ? Am I wrong ?

crissi commented 7 years ago

Same problem here

mlynch commented 7 years ago

So the host thing is a limitation of the underlying URL parsers and technically is correct, so you'll want to use the format myscheme://app/my/path

The second one, does it work if you remove the trailing slash?

jguix commented 7 years ago

Same problem here, it doesn't work removing the slash. Indeed, if I remove the trailing slash and console.log the match I get the following for a URL without params like beatbleeds://account: {"$link":{"path":"/","queryString":"","fragment":"","host":"account","url":"beatbleeds://account/","scheme":"beatbleeds"}}

And for a route with params beatbleeds://terms-conditions/2 (defined as '/terms-conditions/:tab'): {"$link":{"path":"/2","queryString":"","fragment":"","host":"terms-conditions","url":"beatbleeds://terms-conditions/2","scheme":"beatbleeds"}}

So it appends the slash for the route without params. In both cases the host is the intended path. In the route with params, the params are treated as path.