首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ionic 4 Deeplinking如果未安装应用程序,则启动网站

Ionic 4 Deeplinking如果未安装应用程序,则启动网站
EN

Stack Overflow用户
提问于 2020-06-05 18:55:26
回答 1查看 1.4K关注 0票数 1

我在Ionic 4应用程序上工作,当点击外部链接时,我使用deeplink打开应用程序。

我正在使用插件:

代码语言:javascript
运行
复制
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的代码是:

代码语言:javascript
运行
复制
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。

代码语言:javascript
运行
复制
<h1><a href='deeplinktest://example.com/page/?id=3491'>Open App <a></h1>

点击上面的链接,我可以打开应用程序,但当我没有安装应用程序时,android设备上什么也没有发生。是否可以使用我提到的相同链接进行管理?

EN

回答 1

Stack Overflow用户

发布于 2020-06-05 20:29:04

在此块中,您必须处理以下错误:

代码语言:javascript
运行
复制
nomatch => {
    console.error('Got a deeplink that didn\'t match' + JSON.stringify(nomatch));
});

有一个名为In App Browser的插件可以在应用内浏览器中打开链接。安装它,并将您的代码放在nomatch块中:

代码语言:javascript
运行
复制
nomatch => {
    // open the link here using In App Browser
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62213719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档