Deeplink or Redirect to App from URL

Install the deeplinks native plugin. I used these commands to install.

npm install @ionic-native/deeplinks

cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=custom --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=abc.com

After installing, as usual, add DeepLinks as a provider in app.module.ts. Inject it in app.component.ts in the constructor where we will be using it. (code at the end)

Then you have to link your website and your app. For Android,

  1. you can either do it by uploading assetlinks.json to your website OR
  2. linking your website and app in Google search console.

For Approach #1
First step is to create a keystore file and get the fingerprint data. This file is used to sign your app, so you may already have it. Use the fingerprint data in this keystore to generate the assetlinks.json file using the following tool:

Here is a reference for Approach #2 :

At the same time, in the code, in app.component.ts you have to handle the incoming links in the following way:

this.deepLinks.route({ 
          '/login': '/login'
}).subscribe(
          match => {
            console.log('Successfully routed', match);
// use this.route.navigateByUrl here
},
  nomatch => {
  console.log("Deeplink that didn't match", nomatch);
  });

The overall tutorial for this can be found here: How to Setup Universal Links in Ionic (iOS & Android) | Devdactic - Ionic Tutorials

Hope this helps.

1 Like