【发布时间】:2021-02-26 10:03:52
【问题描述】:
我正在从 ionic 应用程序生成一个 android 应用程序,当我使用深度链接单击包含令牌 (http://localhost:8100/signup/token) 的注册链接时,我想打开它。我该怎么做以及如何传递令牌参数?
【问题讨论】:
标签: android ionic-framework deep-linking ionic-native
我正在从 ionic 应用程序生成一个 android 应用程序,当我使用深度链接单击包含令牌 (http://localhost:8100/signup/token) 的注册链接时,我想打开它。我该怎么做以及如何传递令牌参数?
【问题讨论】:
标签: android ionic-framework deep-linking ionic-native
基本上你想要这个插件:https://github.com/ionic-team/ionic-plugin-deeplinks
在 Github 页面中都有解释,但让我们看看:
1 - 安装插件:
cordova plugin add ionic-plugin-deeplinks
--variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com
--variable ANDROID_PATH_PREFIX=/
使用 DEEPLINK_SCHEME + URL_SCHEME 参数,您可以设置检测链接并将用户带到您的应用的域。在上面的例子中:
https://myapp
但这是一项本机功能,您只能在设备上进行测试,而不能使用 ionic serve。
2 - 然后在你的 app.component.ts 中:
this.platform.ready().then(() => {
this.deeplinks.route({
'/about-us': HomePage,
'/products/:productId': HelpPage
}).subscribe(match => {
// match.$route - the route we matched, which is the matched entry from the arguments to route()
// match.$args - the args passed in the link
// match.$link - the full link data
console.log('Successfully matched route', match);
},
nomatch => {
// nomatch.$link - the full link data
console.error('Got a deeplink that didn\'t match', nomatch);
});
});
要获取您的参数,请使用“signup/:token”之类的路由,您可以在 match.$args 中获取该参数(“argument”),如上所示。
【讨论】: