(深層鏈接)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<DeeplinkMatch>
返回一個Observable,每次深層鏈接都會被調用,并且當深層鏈接不符合給定的路徑是會返回錯誤。

routeWithNavController(navController, paths)

這是路由的簡單版本
它引用了來自Ionic的NavController或符合此協議的自定義類:
NavController.push = function(View, Params){}
當路由匹配時,此處理程序將自動導航。 如果需要對匹配的深層鏈接的行為進行更細粒度的控制,請使用普通路由
方法。

參數 類型 詳情
navController Nav 定義一組路徑以匹配傳入的深層鏈接。 路徑采用{'path':data}形式的對象。 如果一個深層鏈接與路徑匹配,則生成的路徑數據對將在允諾結果中返回,然后您可以根據需要在應用中導航。
paths Object

****Returns:** Observable<DeeplinkMatch>
返回一個Observable,它可以在每次深入鏈接進行時解析,并且在深層鏈接不符合給定的路徑時返回錯誤。

DeeplinkMatch

參數 類型 詳情
$route any 匹配路由的路由信息
$args any 任何參數都通過路由參數或GET參數傳遞
$link any 從插件處理的deeplink對象以及路由匹配時可用作“extras”的任何內部本地數據(例如,Facebook有時添加額外的數據)
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容