branch.io deeplink not working as expected in ionic 3

Refresh

April 2019

Views

343 time

1

I have integrated branch.io deeplink in my ionic 3 application. I have successfully generated the link and the link opens up the app. But, I wanted to open a particular page instead of the homepage of the app.

So, I integrated the below code to the desired page:

  dl(){
      // only on devices
      if (!this.platform.is('cordova')) { return }
      const Branch = window['Branch'];

        //only canonicalIdentifier is required
        let properties = {
          canonicalIdentifier: 'content/123',
          canonicalUrl: 'https://example.com/content/123',
          title: 'Content 123 Title',
          contentDescription: 'Content 123 Description ' + Date.now(),
          price: 12.12,
          currency: 'GBD',
          contentIndexingMode: 'private',
          contentMetadata: {
            custom: 'data',
            testing: 123,
            this_is: true
          }
        }
              //create a branchUniversalObj variable to reference with other Branch methods
        let branchUniversalObj = null
        Branch.createBranchUniversalObject(properties).then(function (res) {
          branchUniversalObj = res
          //alert(JSON.stringify(res));          
          // optional fields

        }).catch(function (err) {
          alert('Error: ' + JSON.stringify(err))
        })



        let message = 'Check out this link'

        Branch.initSession(function(data) {
          if (data['+clicked_branch_link']) {
            // read deep link data on click
            alert('Deep Link Data: ' + JSON.stringify(data))
          }
        }).then(function(res) {
          // create deep link
          var analytics = { 
            channel: Date.now() 
          }
          var properties = {}
          branchUniversalObj.generateShortUrl(analytics, properties).then(function (res) {
            alert('Response: ' + JSON.stringify(res.url))


          }).catch(function (err) {
            alert('Error: ' + JSON.stringify(err))
          })

          branchUniversalObj.onLinkShareResponse(function (res) {
            alert('Goosebumps:'  + JSON.stringify(res))
          })
        });




  }

And I added the function to a button click. But, still it opens up the app home page when I click the created link.

1 answers

0

It doesn't looks like you are using the correct setup for your deep link routing. Please reference this Branch documentation for best results: https://docs.branch.io/pages/deep-linking/routing/