Javascript 使用Ionic Native Deeplinks加载角度组件

Javascript 使用Ionic Native Deeplinks加载角度组件,javascript,typescript,ionic4,deep-linking,ionic-native,Javascript,Typescript,Ionic4,Deep Linking,Ionic Native,我一直在互联网上搜索,发现这让我更接近于获得工作的深层链接 使用android模拟器,我可以看到我当前的设置与访问应用程序内的/match路径时尝试使用的路径相匹配 我最终将在推送通知回调函数上触发此代码,但为了进行测试,我将在initializeApp()上调用deeplinks 我像教程建议的那样使用了代码笔,这让我对使用模拟器时发生的事情有了一些了解。当点击链接时,我可以看到一些信息,从昨天开始,我一直在努力找到一种合适的方式来访问这些信息 代码笔示例: <h1><a h

我一直在互联网上搜索,发现这让我更接近于获得工作的深层链接

使用android模拟器,我可以看到我当前的设置与访问应用程序内的/match路径时尝试使用的路径相匹配

我最终将在推送通知回调函数上触发此代码,但为了进行测试,我将在initializeApp()上调用deeplinks

我像教程建议的那样使用了代码笔,这让我对使用模拟器时发生的事情有了一些了解。当点击链接时,我可以看到一些信息,从昨天开始,我一直在努力找到一种合适的方式来访问这些信息

代码笔示例:

<h1><a href="sideline://sidelineapp.io/match">Alert</a></h1>

我的app.component.ts设置如下:

initializeApp() {
    this.platform.ready().then(() => {

      if(localStorage.getItem('config') !== null){
        localStorage.removeItem('config');
      }

      this.splashScreen.hide();

      timer(3000).subscribe(() => {
        this.showSplash = false;
      });

      if (this.platform.is('cordova')) {
        this.oneSignalPush();
        console.log('onesignal');
      }

      this.deeplinks.route({
        '/match': StatsComponent,
      }).subscribe((match) => {
        alert(JSON.stringify(match.$link.path));<-- this alerts the correct path
        this.router.navigate([match.$link.path]);<-- this routes to /match
        console.log('match', match)
      }, (nomatch) => {
        nomatch.$link
        alert(JSON.stringify(nomatch));
        console.log('no match', nomatch)
      })

    });
  }
初始化EAPP(){
this.platform.ready()。然后(()=>{
if(localStorage.getItem('config')!==null){
localStorage.removietem('config');
}
这个.splashScreen.hide();
计时器(3000)。订阅(()=>{
this.showSplash=false;
});
如果(此.platform.is('cordova')){
这个.oneSignalPush();
console.log('onesignal');
}
这条路线({
“/match”:StatComponent,
}).订阅((匹配)=>{

alert(JSON.stringify(match.$link.path));或者,如果您使用的是Ionic,有一种方便的方法可以引用NavController并为您处理实际导航:

this.deeplinks.routeWithNavController(this.navController, {
  '/about-us': AboutPage,
  '/products/:productId': ProductPage
}).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);
  }
);

你也可以从这里获得参考资料。

谢谢Vicky。我已经让它工作了。今天下午我会发送我的代码来说明我是如何工作的