Deep Linking(ディープリンク)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
Tauri アプリケーションを URL のデフォルト・ハンドラーとして設定します。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | | Deep links must be registered in config. Dynamic registration at runtime is not supported. |
| android | | Deep links must be registered in config. Dynamic registration at runtime is not supported. |
| ios | | Deep links must be registered in config. Dynamic registration at runtime is not supported. |
はじめに、「deep-link(ディープリンク)」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add deep-linkyarn run tauri add deep-linkpnpm tauri add deep-linkdeno task tauri add deep-linkbun tauri add deep-linkcargo tauri add deep-link-
src-tauriフォルダで次のコマンドを実行して、このプラグインをCargo.toml内のプロジェクトの依存関係に追加します:cargo add tauri-plugin-deep-link@2.0.0 -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_deep_link::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-deep-linkyarn add @tauri-apps/plugin-deep-linkpnpm add @tauri-apps/plugin-deep-linkdeno add npm:@tauri-apps/plugin-deep-linkbun add @tauri-apps/plugin-deep-link
Android 上のリンクからアプリを開くには、次の二つの方法があります:
- App Links(http/https + host, 検証あり)
アプリリンク を使用する場合、
所定の形式でテキスト応答を返す
.well-known/assetlinks.jsonエンドポイントを持つサーバーが必要です。
[ { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "$APP_BUNDLE_ID", "sha256_cert_fingerprints": [ $CERT_FINGERPRINT ] } }]上記の $APP_BUNDLE_ID は tauri.conf.json > identifier で定義されている値で、 - が _ に置き換えられており、
$CERT_FINGERPRINT はアプリ署名証明書の「SHA256 フィンガープリント」のリストです。
詳細については、Android アプリリンクの検証 を参照してください。
- Custom URI schemes(host 不要、検証不要)
myapp://...のような URI の場合、ファイルをホストすることなくカスタム・スキームを宣言できます。モバイル設定内のschemeフィールドを使用し、hostを省略してください。
URI Uniform Resource Identifiers: 「統一リソース識別子」。インターネット上の情報場所を包括的に示す識別子。サブ・セットとして、「URL」(リソースの場所を識別)と「URN」(リソースの「名前」を識別)の二つがあります。
カスタム・スキーム custom scheme: アプリが独自(カスタム)に定義する URL で、別のアプリからもアプリ内のリソースを参照可能にする方法。
iOS 上のリンクからアプリを開くには、次の二つの方法があります:
- Universal Links(https + host, 検証あり)
ユニバーサル・リンク を使用する場合、所定の形式で JSON 応答を行なう
.well-known/apple-app-site-associationエンドポイントを持つサーバーが必要です:
{ "applinks": { "details": [ { "appIDs": ["$DEVELOPMENT_TEAM_ID.$APP_BUNDLE_ID"], "components": [ { "/": "/open/*", "comment": "Matches any URL whose path starts with /open/" /* 「/open/」で始まるパスで指定された URL に一致 */ } ] } ] }}ngrok 読み「エングロック」: ローカルPC(Localhost)上で実行している Web アプリケーションなどをインターネット上に公開(外部公開)できる「トンネル」ツール。《参考》
上記 json にある “appIDs” の $DEVELOPMENT_TEAM_ID は tauri.conf.json > tauri > bundle > iOS > developmentTeam または TAURI_APPLE_DEVELOPMENT_TEAM 環境変数で定義された値であり、
$APP_BUNDLE_ID は tauri.conf.json > identifier(英語版参考資料)で定義された値です。
自分のドメインがアプリの関連付けを公開するように適切に設定されているかどうかを確認するには、
<host> 部を実際の自分のホスト名に置き換えて、次のコマンドを実行します:
curl -v https://app-site-association.cdn-apple.com/a/v1/<host>詳細については、applinks.details を参照してください。
- Custom URI schemes(host 不要、検証不要)
myapp://...のような URI の場合、モバイル設定で"appLink": falseを指定(あるいは削除)してカスタム・スキームを宣言できます。このプラグインは、あなたのアプリの Info.plist に適切なCFBundleURLTypesエントリを生成します。.well-knownファイルや HTTPS ホストは必要ありません。
Linux および Windows では、「deep link」は新しいアプリ・プロセスへのコマンドライン引数として配信されます。 もし固有のアプリ・インスタンスがイベントを受け取ることを望むのであれば、「deep link」プラグインを「single instance(インスタンスの単一実行)」プラグインと統合します。
- まず、「single instance」プラグインに
deep-link機能を追加する必要があります:
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }- 次に、「single instance」プラグインを、常に最初に登録されるプラグインとなるように設定します:
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { let mut builder = tauri::Builder::default();
#[cfg(desktop)] { builder = builder.plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| { println!("a new app instance was opened with {argv:?} and the deep link event was already triggered"); // when defining deep link schemes at runtime, you must also check `argv` here // 実行時に「deep link」スキーム(設定構成)を定義する場合は、ここで `argv` も確認する必要があります。 })); }
builder = builder.plugin(tauri_plugin_deep_link::init());}argv argument vector: コマンドラインからプログラムに渡された引数を格納した配列。
ユーザーは、引数に URL を含めることで、自分で擬似的(フェイク)な「deep link」を手動トリガーできます。 Tauri は、コマンドラインの引数を設定されたスキームと照合してこれを受け入れます訳注が、 URL が期待している形式と一致しているかどうかを確認する必要はあります。
つまり、Tauri は静的に設定されたスキームでの「deep link」のみを処理しますので、
実行時に登録されたスキームは、Env::args_os を使用して手動で確認する必要があります。
これを受け入れる 原文 mitigate this: 直訳では「これ(擬似的 deep link)を緩和する」ですが詳細不明ですので、スキームを緩和・軽減するというような意味として上記訳としています。
tauri.conf.json > plugins > deep-link には、自分のアプリケーションに関連付けたいモバイル・ドメイン/スキームとデスクトップ・スキームを設定します。
モバイル用カスタム・スキーム(サーバー不要):
{ "plugins": { "deep-link": { "mobile": [ { "scheme": ["ovi"], "appLink": false } ] } }}これにより、Android および iOS 用に ovi://* スキームが登録されます。
App Link / Universal Link(認証済み https + host):
{ "plugins": { "deep-link": { "mobile": [ { "scheme": ["https"], "host": "your.website.com" /*自分のホスト・サイト*/, "pathPrefix": ["/open"], "appLink": true } ] } }}これにより、https://your.website.com/open/* が「アプリ・リンク/ユニバーサル・リンク」として登録されます。
デスクトップ・カスタム・スキーム:
{ "plugins": { "deep-link": { "desktop": { "schemes": ["something", "my-tauri-app"] } } }}「deep link」プラグインは、JavaScript と Rust の両方で利用できます。
アプリ実行中に「deep link」がアプリを起動すると、「onOpenUrl コールバック」が呼び出されます。アプリが deep link 経由で開かれたかどうかを検出するには、アプリ起動時に getCurrent を使用します。
import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link';// `"withGlobalTauri": true` を使用する場合は、// const { getCurrent, onOpenUrl } = window.__TAURI__.deepLink; を使用できます。
const startUrls = await getCurrent();if (startUrls) { // アプリはたぶん deep link 経由で起動されています // getCurrent の戻り値は onOpenUrl がトリガーされるたびに更新されることにも注意してください。}
await onOpenUrl((urls) => { console.log('deep link:', urls);});アプリの実行中に「deep link」がアプリを起動すると、このプラグインの「on_open_url クロージャ」が呼び出されます。アプリが deep link 経由で開かれたかどうかを検出するには、アプリ起動時に get_current を使用してください。
use tauri_plugin_deep_link::DeepLinkExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { // getCurrent の戻り値は onOpenUrl がトリガーされるたびに更新されることにも注意してください。 let start_urls = app.deep_link().get_current()?; if let Some(urls) = start_urls { // アプリはたぶん deep link 経由で起動されています println!("deep link URLs: {:?}", urls); }
app.deep_link().on_open_url(|event| { println!("deep link URLs: {:?}", event.urls()); }); Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}上記の「設定」の項では、あなたのアプリケーションで「静的 deep link スキーム」を定義する方法について説明しています。
Linux および Windows では、register という Rust 関数を経由して、実行時にあなたのアプリケーションにスキームを関連付けることも可能です。
以下のスニペット事例では、実行時に my-app のスキームが登録されます。そして、アプリを初めて実行した後に、
オペレーティング・システムが、アプリケーションで my-app://* にある各 URL を開きます:
use tauri_plugin_deep_link::DeepLinkExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { #[cfg(desktop)] app.deep_link().register("my-app")?; Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}ヘルパー関数 helper function: よく用いられる処理内容を「独自の関数」として定義し、いつでも呼び出せるようにしたもの。同じ内容の処理を何度も記述する必要がなくなり省力化の手助け(ヘルプ)になり、処理コードの再利用や可読性の向上にもつながる仕組みです。
自分のアプリケーションの deep link をテストする場合には、いくつか注意すべき点があります。
deep link は、デスクトップ機にインストールされているアプリケーションに対してのみトリガーされます。
Linux と Windows では、register_all という Rust 関数を使用することで、これを回避できます。
この関数は、現在の実行可能ファイルをトリガーするために構成されたすべてのスキームを登録します:
use tauri_plugin_deep_link::DeepLinkExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { #[cfg(any(windows, target_os = "linux"))] { use tauri_plugin_deep_link::DeepLinkExt; app.deep_link().register_all()?; } Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}Windows で deep link をトリガーするには、ブラウザーで <scheme>://url を開くか、ターミナルで次のコマンドを実行します:
start <scheme>://urlLinux で deep link をトリガーするには、ブラウザーで <scheme>://url を開くか、ターミナルで xdg-open を実行します:
xdg-open <scheme>://urliOS で app link(アプリリンク)をトリガーするには、ブラウザで https://<host>/path URL を開きます。シミュレーターの場合は、simctl CLI を利用してターミナルから直接リンクを開くことができます:
xcrun simctl openurl booted https://<host>/pathAndroid で app link(アプリリンク)をトリガーするには、ブラウザで https://<host>/path URL を開きます。エミュレータの場合は、adb CLI を利用してターミナルから直接リンクを開くことができます:
adb shell am start -a android.intent.action.VIEW -d https://<host>/path <bundle-identifier>デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "$schema": "../gen/schemas/mobile-schema.json", "identifier": "mobile-capability", "windows": ["main"], "platforms": ["iOS", "android"], "permissions": [ // 通常、deep link をリッスン(応答待機)するには、「core:event:default」が必要です。 "core:event:default", "deep-link:default" ]}Default Permission
Allows reading the opened deep link via the get_current command
This default permission set includes the following:
allow-get-current
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the get_current command without any pre-configured scope. |
|
|
Denies the get_current command without any pre-configured scope. |
|
|
Enables the is_registered command without any pre-configured scope. |
|
|
Denies the is_registered command without any pre-configured scope. |
|
|
Enables the register command without any pre-configured scope. |
|
|
Denies the register command without any pre-configured scope. |
|
|
Enables the unregister command without any pre-configured scope. |
|
|
Denies the unregister command without any pre-configured scope. |
【※ この日本語版は、「Sep 29, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT