Cordova深层链接-未从通用链接中检测到查询参数

问题描述 投票:0回答:1

我正在尝试使用ionic-plugin-deeplinks插件将通用链接添加到Cordova应用程序。

根据this issue,查询参数应该开箱即用。

对我来说是通用链接可以正常工作,但带有查询参数的链接除外

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

当我单击电子邮件中的链接时,queryString字段为总是空字符串

enter image description here

我是否缺少某些内容,是否需要使插件能够检测查询参数?

这是我正在使用的代码:

const deepLinkRoutes = {
  '/user/login': {
    neo: 'showLogin',
    resetUrl: '/',
  },
  '/user/forgot-password': {
    neo: '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);
};
ios cordova ionic-framework hybrid-mobile-app ios-universal-links
1个回答
0
投票

线索:

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

似乎插件正在使用window.location.href来检测查询参数。

因为我使用cordova-plugin-inappbrowser,所以href是用于服务应用程序内容的Ionic引擎的本地主机的别名,因此永远找不到查询参数。

代码:

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
    });
  })
  // ...
}

这是问题,尚不确定解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.