ios - Cordova 深层链接 - 未从通用链接中检测到查询参数
问题描述
我正在尝试使用ionic-plugin-deeplinks插件将通用链接添加到 Cordova 应用程序。
根据这个问题,查询参数应该开箱即用。
对我来说,通用链接可以正常工作,但带有查询参数的链接除外。
例如。https://my-site.com/?olddeeplinking=resetpassword&token=123
当我单击电子邮件中的链接时,queryString 字段始终为空字符串。
我是否遗漏了什么,我是否需要启用插件来检测查询参数?
这是我正在使用的代码:
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);
};
更新:看起来在 Android 上收到的意图总是 /user/login 即使通用链接没有它。可能是什么原因造成的?
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
解决方案
线索:
看起来deeplinks插件正在window.location.href
用于检测查询参数。
由于我使用的是cordova-plugin-ionic-webview,href
它始终是用于为应用程序内容提供服务的离子引擎的本地主机的别名,因此永远找不到查询参数。
深度链接插件代码:
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
});
})
// ...
}
这就是问题所在,但尚不确定解决方案。
推荐阅读
- python - 使用python将一个csv文件的内容添加到另一个文件
- c# - 将所有 string[] 转换为 int[] 并消除错误消息
- terraform - Terraform:错误查找:参数 1 应该是类型映射,得到类型字符串:
- django - 是否可以使用 URL 参数登录用户?(DJANGO)
- python-3.6 - 简单的 Salesforce 查询_更多永无止境
- php - 是php-mysql:根据涉及PHP变量的条件更新具有不同值的列
- azure - Azure 逻辑应用 - 能否创建此自定义 RBAC 规则?
- javascript - 是否有路由 setState redux 操作的标准方法?
- r - 在函数中包装 Boot 调用会产生错误
- eclipse - 如何在 Eclipse 中使用 Google Cloud Repositories?