(深层链接)Deeplinks

Deeplinks

此插件处理iOS和Android上的深层链接,用于自定义网址方案链接和通用应用链接。
Repo(备用): https://github.com/ionic-team/ionic-plugin-deeplinks

Installation(安装)

1.安装Cordova和Ionic原生插件:

$ ionic cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/
$ npm install --save @ionic-native/deeplinks

2.添加插件到app's module

Supported platforms(支持平台)

Android
Browser
iOS

Usage(用法)

import { Deeplinks } from '@ionic-native/deeplinks';

constructor(private deeplinks: Deeplinks) { }

this.deeplinks.route({
     '/about-us': AboutPage,
     '/universal-links-test': 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);
   });

或者,如果您使用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);
  });

参见Ionic Deeplinks Demo有关如何检索NavController的示例
在运行时引用。

Instance Members(实例成员)

route(paths)

定义一组路径以匹配传入的深层链接。

参数 类型 详情
paths paths 定义一组路径以匹配传入的深层链接。 路径采用{'path':data}形式的对象。 如果一个深层链接与路径匹配,则生成的路径数据对将在允诺结果中返回,然后您可以根据需要在应用中导航。

****Returns:** Observable
返回一个Observable,每次深层链接都会被调用,并且当深层链接不符合给定的路径是会返回错误。

routeWithNavController(navController, paths)

这是路由的简单版本
它引用了来自Ionic的NavController或符合此协议的自定义类:
NavController.push = function(View, Params){}
当路由匹配时,此处理程序将自动导航。 如果需要对匹配的深层链接的行为进行更细粒度的控制,请使用普通路由
方法。

参数 类型 详情
navController Nav 定义一组路径以匹配传入的深层链接。 路径采用{'path':data}形式的对象。 如果一个深层链接与路径匹配,则生成的路径数据对将在允诺结果中返回,然后您可以根据需要在应用中导航。
paths Object

****Returns:** Observable
返回一个Observable,它可以在每次深入链接进行时解析,并且在深层链接不符合给定的路径时返回错误。

DeeplinkMatch

参数 类型 详情
$route any 匹配路由的路由信息
$args any 任何参数都通过路由参数或GET参数传递
$link any 从插件处理的deeplink对象以及路由匹配时可用作“extras”的任何内部本地数据(例如,Facebook有时添加额外的数据)

你可能感兴趣的:((深层链接)Deeplinks)