1

I am working on Ionic 4 app and I am using deeplink to open app when clicked on a external link.

I am using plugin:

cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=deeplinktest --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/
npm install @ionic-native/deeplinks

and code for opening app is:

openAppFromLink() {
    this.deeplinks.routeWithNavController(this.navCtrl, {
      '/pageName/:id': {}
    }).subscribe(match => {
      if (localStorage.getItem('loggedInUser')) {
        let navigationExtras: NavigationExtras = {
          state: {
            id: match.$args.id,
            isDeeplink: true
          }
        };
        console.log('Successfully matched route' + JSON.stringify(match));
        this.router.navigateByUrl(this.router.routerState.snapshot.url + '/pageName', navigationExtras);
      } else {
        console.log('opening in system browser');
        window.open('https://example.com', '_system');
      }
    }, nomatch => {
      console.error('Got a deeplink that didn\'t match' + JSON.stringify(nomatch));
    });
  }

I want to open a website or a playstore if user don't have app install on his device.

<h1><a href='deeplinktest://example.com/page/?id=3491'>Open App <a></h1>

on click of above link I am able to open app but when I don't have app installed nothing happens on android device. Can this managed with the same link I mentioned?

Ragesh Pikalmunde
  • 1,333
  • 1
  • 20
  • 44

1 Answers1

0

in this block you have to handle the error:

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

there is a plugin named In App Browser that opens links in in-app-browser. install it and put your code in nomatch block:

nomatch => {
    // open the link here using In App Browser
});
Mahdi Zarei
  • 5,644
  • 7
  • 24
  • 54
  • what I want is when app is not installed on device and user click on given link so I would be able to open website...in this case there is no code...I want to manage that deeplink url scheme. – Ragesh Pikalmunde Jun 05 '20 at 13:06
  • @RageshPikalmunde Don't know how to do that. but I have a suggestion. you can do what I said and in the link search the app on google. as a result Google will show the website on first link probably. – Mahdi Zarei Jun 05 '20 at 13:47
  • Not yet...still trying – Ragesh Pikalmunde Jun 08 '20 at 04:11