我在Ionic 4应用程序上工作,当点击外部链接时,我使用deeplink打开应用程序。
我正在使用插件:
cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=deeplinktest --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/
npm install @ionic-native/deeplinks
打开app的代码是:
openAppFromLink() {
this.deeplinks.routeWithNavController(this.navCtrl, {
'/pageName/:id': {}
}).subscribe(match => {
if (localStorage.getItem('loggedInUser')) {
let navigationExtras: NavigationExtras = {
state: {
id: match.$args.id,
isDeeplink: true
}
};
console.log('Successfully matched route' + JSON.stringify(match));
this.router.navigateByUrl(this.router.routerState.snapshot.url + '/pageName', navigationExtras);
} else {
console.log('opening in system browser');
window.open('https://example.com', '_system');
}
}, nomatch => {
console.error('Got a deeplink that didn\'t match' + JSON.stringify(nomatch));
});
}
如果用户没有在他的设备上安装应用程序,我想打开一个网站或playstore。
<h1><a href='deeplinktest://example.com/page/?id=3491'>Open App <a></h1>
点击上面的链接,我可以打开应用程序,但当我没有安装应用程序时,android设备上什么也没有发生。是否可以使用我提到的相同链接进行管理?
发布于 2020-06-05 20:29:04
在此块中,您必须处理以下错误:
nomatch => {
console.error('Got a deeplink that didn\'t match' + JSON.stringify(nomatch));
});
有一个名为In App Browser的插件可以在应用内浏览器中打开链接。安装它,并将您的代码放在nomatch块中:
nomatch => {
// open the link here using In App Browser
});
https://stackoverflow.com/questions/62213719
复制相似问题