Ionic 3 native deeplinking

Viewed 4557

Managed to install and setup the native deeplinking module for Ionic.

App loads up fine even in cold state, where it is fully shutdown.

However, my route doesn't take me to the correct page. It just displays the last page the app was one, or the main page if it starts the application from cold state.

app.component.ts

...
import { Deeplinks } from '@ionic-native/deeplinks';
import { Detail1Page } from '../pages/layout/app1/detail1/detail1';
...
constructor(private deeplinks: Deeplinks.........
...
this.platform.ready().then(() => {
this.splashScreen.hide();
this.deeplinks.route({
  '/item/:itemId': Detail1Page
}).subscribe((match) => {
    console.log('Successfully matched route', JSON.stringify(match));
  }, (nomatch) => {
    console.error('Got a deeplink that didn\'t match', JSON.stringify(nomatch));
  });
}
...

The console log shows:

Successfully matched route {"$args":{"itemId":"9"},"$link":{"path":"/item/9","queryString":"","fragment":"","host":"my.app.com","url":"https://my.app.com/item/9","scheme":"https"}}

app.module.ts

...
import { Deeplinks } from '@ionic-native/deeplinks';
...
providers: [
    Deeplinks,
...

detail1.ts

...
this.itemId = this.navParams.get('itemId');
...

Your help is greatly appreciated - been working on this the whole day :)

2 Answers

I know its too late but still, it can be helpful for someone. I am redirecting the user after subscribing so you can put more logic if the user is logged in on not or so you can change things accordingly

this.deeplinks.route({
  '/item/:itemId': {}
}).subscribe(match => { 
    console.log('Successfully matched route' + JSON.stringify(match));
    this.nav.push(Detail1Page, { issueId: match.$args.issueId});

  }
}, nomatch => {
  console.error('Got a deeplink that didn\'t match' + JSON.stringify(nomatch));
});
Related