首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Deeplinks给出了空路径

Deeplinks给出了空路径
EN

Stack Overflow用户
提问于 2018-08-16 13:37:10
回答 2查看 962关注 0票数 2

我在实现DeepLinks时遇到了问题。我可以从URL打开应用程序,比如myapp://myapp.com/ open。但它不能处理它的路径。它只会打开程序。

我打开它时:

代码语言:javascript
运行
复制
 this.deeplinks.route({
  '/route': RoutePage
    }).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);
});

但是,我没有收到任何控制台日志,路径是空的,只需要以下消息:

我的config.xml

代码语言:javascript
运行
复制
 <plugin name="ionic-plugin-deeplinks" spec="^1.0.17">
    <variable name="URL_SCHEME" value="iskibris" />
    <variable name="DEEPLINK_SCHEME" value="https" />
    <variable name="DEEPLINK_HOST" value="iskibris.com" />
    <variable name="ANDROID_PATH_PREFIX" value="/" />
    <variable name="ANDROID_2_PATH_PREFIX" value="/" />
    <variable name="ANDROID_3_PATH_PREFIX" value="/" />
    <variable name="ANDROID_4_PATH_PREFIX" value="/" />
    <variable name="ANDROID_5_PATH_PREFIX" value="/" />
    <variable name="DEEPLINK_2_SCHEME" value="" />
    <variable name="DEEPLINK_2_HOST" value="" />
    <variable name="DEEPLINK_3_SCHEME" value="" />
    <variable name="DEEPLINK_3_HOST" value="" />
    <variable name="DEEPLINK_4_SCHEME" value="" />
    <variable name="DEEPLINK_4_HOST" value="" />
    <variable name="DEEPLINK_5_SCHEME" value="" />
    <variable name="DEEPLINK_5_HOST" value="" />
</plugin>

打电话给这个应用的链接://iskibris.com/ help,有人能帮我吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-16 15:37:20

Ionic Deeplinks有两个方法来打开另一个页面。

  1. 路由
  2. routeWithNavController

当使用route方法时,您应该使用nav.push导航另一个页面。您可以在app.component.ts中实现它,如下所示。

代码语言:javascript
运行
复制
  @ViewChild(Nav) nav:Nav;
  constructor(private deeplinks: Deeplinks) {
    platform.ready().then(() => {

       this.deeplinks.route({
         '/about': AboutPage
       }).subscribe(match => {
         this.nav.push(AboutPage);
       }, nomatch => {
         console.error('Got a deeplink that didn\'t match', nomatch);
      });

    });
  }
}

或者使用routeWithNavControllerNavController进行引用并处理实际导航。routeWithNavController方法可以在app.component.ts中实现如下所示

代码语言:javascript
运行
复制
      @ViewChild(Nav) nav:Nav;

      constructor(private deeplinks: Deeplinks) {

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

         this.deeplinks.routeWithNavController(this.nav, {
            '/about': AboutPage

          }).subscribe(match => {

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

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

还有一点,在您的config.xml中,<variable name="URL_SCHEME" value="iskibris" />应该更改为<variable name="URL_SCHEME" value="myapp" />

票数 1
EN

Stack Overflow用户

发布于 2021-08-03 01:28:06

对我来说,唯一可行的方法是,奇怪的是,使用routeWithNavController方法并在第二个参数上传递一个空对象。顺便说一下,我正在Ionic 3上测试iPhone仿真器。

以下是测试结果:

代码语言:javascript
运行
复制
/**
 * Using the routeWithNavController method and passing an empty object on the second parameter
 * WORKS!!
 * Did open the app and fired the "match" callback with the info of the clicked link
 */
this.platform.ready().then(() => {
  this.deeplinks.routeWithNavController(this.nav, {
    // Nothing here. Empty object
  }).subscribe((match) => {
    alert('Match');
    alert(JSON.stringify(match));
  }, (nomatch) => {
    alert('No Match');
    alert(JSON.stringify(nomatch));
  });
});

下面的示例没有使用

代码语言:javascript
运行
复制
/**
 * Using the routeWithNavController method and passing an object with a "what would be" route on the second parameter
 * DOESN`T WORK
 * Did open the app but didn't fire any of the callbacks. Neither "match" or "nomatch"
 */
this.platform.ready().then(() => {
  this.deeplinks.routeWithNavController(this.nav, {
    '/': {}
  }).subscribe((match) => {
    alert('Match');
    alert(JSON.stringify(match));
  }, (nomatch) => {
    alert('No Match');
    alert(JSON.stringify(nomatch));
  });
});
代码语言:javascript
运行
复制
/**
 * Using the route method and passing an object empty object
 * DOESN'T WORK (kinda)
 * Did open the app and fired the nomatch callback (after all, no route specified)
 */
this.platform.ready().then(() => {
  this.deeplinks.route({
    // Nothing here. Empty object,
  }).subscribe((match) => {
    alert('Match');
    alert(JSON.stringify(match));
  },
  (nomatch) => {
    alert('No Match');
    alert(JSON.stringify(nomatch));
  });
});
代码语言:javascript
运行
复制
/**
 * Using the route method and passing object with a "what would be" route on the second parameter
 * By the way, here I tried both links:
 * myapp://myapp.domain.com/
 * myapp://myapp.domain.com
 * DOESN`T WORK
 * Did open the app but didn't fire any of the callbacks. Neither "match" or "nomatch"
 */
this.platform.ready().then(() => {
  this.deeplinks.route({
    '/': {},
  }).subscribe((match) => {
    alert('Match');
    alert(JSON.stringify(match));
  },
  (nomatch) => {
    alert('No Match');
    alert(JSON.stringify(nomatch));
  });
});

因为只有第一个工作正常,所以我不得不处理match对象数据并自己执行路由,如下所示:

代码语言:javascript
运行
复制
this.deeplinks.routeWithNavController(this.nav, {}).subscribe((match) => {
  if (match.$link.path == "/list") {
    this.nav.setRoot(ListPage);
  }
}, (nomatch) => {});

下面是我的deeplinks工作app.component.ts的完整代码:

代码语言:javascript
运行
复制
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { Deeplinks } from '@ionic-native/deeplinks';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = HomePage;

  pages: Array<{title: string, component: any}>;

  constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public deeplinks: Deeplinks) {
    this.initializeApp();

    // used for an example of ngFor and navigation
    this.pages = [
      { title: 'Home', component: HomePage },
      { title: 'List', component: ListPage }
    ];
  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      this.deeplinks.routeWithNavController(this.nav, {}).subscribe((match) => {
        if (match.$link.path == "/list") {
          this.nav.setRoot(ListPage);
        }
      }, (nomatch) => {});
    });
  }

  openPage(page) {
    // Reset the content nav to have just this page
    // we wouldn't want the back button to show in this scenario
    this.nav.setRoot(page.component);
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51878423

复制
相关文章

相似问题

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