Angular - 尝试使用深层链接但只有应用程序正在打开,路由不起作用

Angular - trying to use deeplinks but only the app is opening, routing not working

我正在尝试使用深层链接,但只有应用程序正在打开。路由不工作。

这是我的代码:

import { Component, ViewChild } from ‘@angular/core’;
import { App, Platform, Nav, NavController } from ‘ionic-angular’;
import { StatusBar } from ‘@ionic-native/status-bar’;
import { SplashScreen } from ‘@ionic-native/splash-screen’;
import { Deeplinks } from ‘@ionic-native/deeplinks’;
import { HomePage } from ‘…/pages/home/home’;
import { HarryPage } from ‘…/pages/harry/harry’;

@Component({
    templateUrl: ‘app.html’
})

export class MyApp {
    @ViewChild(‘myNav’) nav: Nav;
    rootPage:any = HomePage;

    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private deeplinks: Deeplinks) {
        platform.ready().then(() => {
            statusBar.styleDefault();
            splashScreen.hide();
        });
        this.deeplinks.routeWithNavController( this.nav, {
            ‘/harry’: HarryPage,
            ‘/’ :HomePage
        }).subscribe( (match)=>{
                console.log(match.$route);
                // alert(JSON.stringify(match))
            }, (noMatch)=>{
                // alert(JSON.stringify(noMatch));
            })
    }
}

每当我尝试访问 /harry 路由时,只有主页打开。

platform.ready() 回调中尝试 deeplinks 逻辑。

      @ViewChild(Nav) nav:Nav;

      constructor(private deeplinks: Deeplinks) {

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

         this.deeplinks.routeWithNavController(this.nav, {
            '/harry': HarryPage,
            '/' : HomePage

          }).subscribe(match => {

            console.log('Successfully matched route', JSON.stringify(match, null, 2));
          }, nomatch => {

            console.error('Got a deeplink that didn\'t match', nomatch);
          });
        });  
 }

如果您将相同的代码放入根页面,它会起作用,如果您遵循他们的文档,那么什么都不会起作用。