【问题标题】:Ionic 3 native deeplinkingIonic 3 原生深度链接
【发布时间】:2018-05-03 12:57:10
【问题描述】:

设法为 Ionic 安装和设置本机深度链接模块。

应用程序即使在完全关闭的冷状态下也能正常加载。

但是,我的路线没有将我带到正确的页面。它只显示应用程序的最后一页,或者如果它从冷状态启动应用程序,则显示主页。

app.component.ts

...
import { Deeplinks } from '@ionic-native/deeplinks';
import { Detail1Page } from '../pages/layout/app1/detail1/detail1';
...
constructor(private deeplinks: Deeplinks.........
...
this.platform.ready().then(() => {
this.splashScreen.hide();
this.deeplinks.route({
  '/item/:itemId': Detail1Page
}).subscribe((match) => {
    console.log('Successfully matched route', JSON.stringify(match));
  }, (nomatch) => {
    console.error('Got a deeplink that didn\'t match', JSON.stringify(nomatch));
  });
}
...

控制台日志显示:

Successfully matched route {"$args":{"itemId":"9"},"$link":{"path":"/item/9","queryString":"","fragment":"","host":"my.app.com","url":"https://my.app.com/item/9","scheme":"https"}}

app.module.ts

...
import { Deeplinks } from '@ionic-native/deeplinks';
...
providers: [
    Deeplinks,
...

detail1.ts

...
this.itemId = this.navParams.get('itemId');
...

非常感谢您的帮助 - 整天都在努力解决这个问题 :)

【问题讨论】:

    标签: angular ionic-framework ionic3 deep-linking


    【解决方案1】:

    我知道为时已晚,但仍然可以对某人有所帮助。我在订阅后重定向用户,因此如果用户未登录,您可以添加更多逻辑,或者您可以相应地更改内容

    this.deeplinks.route({
      '/item/:itemId': {}
    }).subscribe(match => { 
        console.log('Successfully matched route' + JSON.stringify(match));
        this.nav.push(Detail1Page, { issueId: match.$args.issueId});
    
      }
    }, nomatch => {
      console.error('Got a deeplink that didn\'t match' + JSON.stringify(nomatch));
    });
    

    【讨论】:

      【解决方案2】:

      我昨天也遇到了同样的问题...

      就我而言,我没有在 app.module 中注册页面的任何地方。

      @NgModule({
        declarations: [
          MyPage
        ],
        imports: [
          IonicPageModule.forChild(MyPage)
        ],
        entryComponents: [
          MyPage
        ]
      })
      export class MyPageModule {}
      

      对我来说,我缺少 IonicPageModule.forChild 参考。 这是文档页面,其中讨论了为深度链接设置页面。 https://ionicframework.com/docs/api/navigation/IonicPage/#usage

      【讨论】:

      • 我放弃了 ionic 的 dreplinking,去了 branch.io。我做的最好的事情:)
      • 噢,(branch.io) 看起来不错,我得去看看。希望我的回答可以帮助其他人。
      • Branch 非常棒且易于集成。你会喜欢的。
      猜你喜欢
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 2010-12-06
      • 2018-01-28
      • 1970-01-01
      相关资源
      最近更新 更多