0

I am trying to add Universal Linking to a Cordova App using the ionic-plugin-deeplinks plugin.

According to this issue query parameters should work out of the box.

Universal Links for me work correctly except for links with query parameters.

Eg. https://my-site.com/?olddeeplinking=resetpassword&token=123


When I click on the link in an email the queryString field is always an empty string.

enter image description here

Am I missing something, do I need to enable the plugins to detect query params?

Here is the code that I'm using:

const deepLinkRoutes = {
  '/user/login': {
    action: 'showLogin',
    resetUrl: '/',
  },
  '/user/forgot-password': {
    action: 'showForgotPassword',
    resetUrl: '/',
  },
  ...
};

export const _getIonicRoutes = () => Object.keys(deepLinkRoutes)
  .reduce((links, route) => {
    links[route] = { target: '', parent: '' };
    return links;
  }, {});

export const handleUniversalLinks = () => {
  const ionicRoutes = _getIonicRoutes();
  const sy = obj => JSON.stringify(obj);
  const matchFn = ({ $link, $route, $args }) => {
    console.log('Successfully matched route', $link, $route, $args);
    alert(`Successfully matched route: ${sy($link)}, ${sy($route)}, ${sy($args)}`);
    return history.push($link.path);
  };
  const noMatchFn = ({ $link, $route, $args }) => {
    console.log('NOT Successfully matched route', $link, $route, $args);
    alert(`NOT Successfully matched route: ${sy($link)}, ${sy($route)}, ${sy($args)}`);
    return history.push($link.path);
  };
  window.IonicDeeplink.route(ionicRoutes, matchFn, noMatchFn);
};

UPDATE: It looks like the intent received on Android is always /user/login even though the Universal Link does not have it. What could be causing that?

2019-10-21 17:22:47.107 30389-30389/? D/MessageViewGestureDetector: HitTestResult type=7, extra=https://nj.us.gpd.my_company-dev.com/user/login 2019-10-21 17:22:47.139 1128-1183/? I/ActivityManager: START u0 {act=android.intent.action.VIEW dat=https://nj.us.gpd.williamhill-dev.com/... cmp=us.my_company.nj.sports.gpd/.MainActivity} from uid 10147

Gabe
  • 5,997
  • 5
  • 46
  • 92
  • **I will give 100 bounty to whoever helps me solve this. Thx** – Gabe Oct 21 '19 at 20:03
  • **UPDATE:** the issue was just that all links in the email were copied from a single one and edited. 4hs of my life that will never come back. Need sleep. – Gabe Oct 21 '19 at 23:35

1 Answers1

0

A clue:

It looks like the deeplinks plugin is using window.location.href to detect the query parameter.

Since I am using cordova-plugin-ionic-webview the href is always the alias used for localhost of the Ionic engine serving the App contents, so the query parameters are never found.

Deeplinks plugin code:

https://github.com/ionic-team/ionic-plugin-deeplinks/blob/master/src/browser/DeeplinkProxy.js#L40

function locationToData(l) {
  return {
    url: l.href,
    path: l.pathname,
    host: l.hostname,
    fragment: l.hash,
        scheme: parseSchemeFromUrl(l.href),
        queryString: parseQueryStringFromUrl(l.href)
  }
}

onDeepLink: function(callback) {
  // Try the first deeplink route
  setTimeout(function() {
    callback && callback(locationToData(window.location), {
      keepCallback: true
    });
  })
  // ...
}

This is the problem, not sure on the solution yet though.

Gabe
  • 5,997
  • 5
  • 46
  • 92
  • I added an `alert(window.location.href)` on app launch and the `href` is as expected the alias used for the Ionic engine. The `$link` argument though is taken from the link that was clicked. How is it possible? it's using window.location.href.. confused). And why it cannot find the query parameter from the href then? :( – Gabe Oct 21 '19 at 23:20
  • See my last comment under the question. There was never a problem. – Gabe Oct 21 '19 at 23:37