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 220 forks source link

IOS Deeplinks Opens App but always fall in nomatch #241

Closed gfarid closed 3 years ago

gfarid commented 3 years ago

info :ionic 5 ,angular 9

i encounter an issue , always fall in the nomatch subscription . the url is something like this 'myapp://payload=12345' and always i fall in nomacth. inside this object (nomatch) { host:'payload=12345', path:'' }

i tried to change the url to myapp://app/payload=12345 and now { host: 'app', path:'/payload=12345' }

but still fall in nomatch

my code is like this

this.deeplinks.route({ '': 'post', '/': 'post', '/payload': 'post', '/payload=': 'post', }).subscribe( match => { console.log('Successfully matched route', match); }, nomatch => { console.error(Got a deeplink that didn't match, nomatch); });

by the way according to the documentation , we need to provide page/class to the route and this no longer works, and failed on deeplink.js line 129 >>> var routeParts = route.split('/'); >>> route should be string ,can't be page or class

this.deeplinks.route({ '/about-us': AboutPage, }).subscribe(match => { console.log('Successfully matched route', match); }, nomatch => { console.error('Got a deeplink that didn\'t match', nomatch); });

kensodemann commented 3 years ago

Just to update with what we were discussing via another thread:

After studying this code for a bit: https://github.com/ionic-team/ionic-plugin-deeplinks/blob/master/www/deeplink.js#L37-L82, it appears that the README.md is wrong.

A few observations:

This code loops through the "paths" object. "targetPath" will be the property name, and line 51 will get that property's value and treat it as a path. So the documentation says to do something like the following where the property would specify a path and the value of the property would be some string or object could be then used by your app to specify internal navigation:

    this.deeplinks
      .route({
        '/black': 'black',
        '/dark': 'dark',
        '/green': 'green',
        '/herbal': 'herbal',
        '/oolong': 'oolong'
      })

But the reality of the code is more like this, where the property name is just a key that is never returned or anything, and the value is the actual route that is being matched:

    this.deeplinks
      .route({
        black: '/black',
        dark: '/dark',
        green: '/green',
        herbal: '/herbal',
        oolong: '/oolong'
      })

It looks like the PR #242 would properly address this and bring the plugin back into compliance with the documentation (though the docs could be better for modern Ionic as they seem to be somewhat version 3 centric (see note below)).

I have not tried it yet with a route like "myapp://payload=12345" or a route with query parameters (which is more what I would expect rather than what you have), but I will try that next.

So, reversing your setup may help.

A final fallback may be to fork the plugin and re-write the deeplink.js portion of it such that the matching algorithm used matches what you need within your application.

by the way according to the documentation , we need to provide page/class to the route and this no longer works, and failed on deeplink.js line 129 >>> var routeParts = route.split('/'); >>> route should be string ,can't be page or class

The documentation that references using a page class looks really really old. That would have relied on functionality that existing in the custom router we used way back in Ionic Framework v3, and even then it would not be recommended as it would break lazy loading.