@tauri-apps/plugin-deep-link
函式
getCurrent()
function getCurrent(): Promise<string[] | null>
取得觸發深度連結的當前 URL。在應用程式載入時使用此功能,以檢查您的應用程式是否透過深度連結啟動。
回傳
Promise
<string
[] | null
>
範例
import { getCurrent } from '@tauri-apps/plugin-deep-link';const urls = await getCurrent();
- Windows / Linux:此函式讀取命令列參數,並檢查是否只有一個值,且該值必須是具有符合已組態值的 scheme 的 URL。
請注意,當使用 [Self::register
] 動態註冊深度連結 scheme 時,您必須手動檢查參數。此外,深度連結可能已作為 CLI 參數提供,因此您應檢查其格式是否符合您的預期。
自從
2.0.0
來源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L23
isRegistered()
function isRegistered(protocol): Promise<boolean>
檢查應用程式是否為指定協定的預設處理程序。
參數
參數 | 類型 | 描述 |
---|---|---|
protocol | string | 協定的名稱,不包含 :// 。 |
回傳
Promise
<boolean
>
範例
import { isRegistered } from '@tauri-apps/plugin-deep-link';await isRegistered("my-scheme");
- macOS / Android / iOS:不支援。
自從
2.0.0
來源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L80
onOpenUrl()
function onOpenUrl(handler): Promise<UnlistenFn>
用於 deep-link://new-url
事件的輔助函式,以便在應用程式運行時每次觸發協定時運行函式。在應用程式載入時使用 getCurrent
,以檢查您的應用程式是否透過深度連結啟動。
參數
參數 | 類型 |
---|---|
handler | (urls ) => void |
回傳
Promise
<UnlistenFn
>
範例
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';await onOpenUrl((urls) => { console.log(urls) });
- Windows / Linux:若沒有 single-instance 插件則不支援。作業系統將產生一個新的應用程式實例,並將 URL 作為 CLI 參數傳遞。
自從
2.0.0
來源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L99
register()
function register(protocol): Promise<null>
將應用程式註冊為指定協定的預設處理程序。
參數
參數 | 類型 | 描述 |
---|---|---|
protocol | string | 協定的名稱,不包含 :// 。例如,如果您希望您的應用程式處理 tauri:// 連結,請使用 tauri 作為協定呼叫此方法。 |
回傳
Promise
<null
>
範例
import { register } from '@tauri-apps/plugin-deep-link';await register("my-scheme");
- macOS / Android / iOS:不支援。
自從
2.0.0
來源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L42
unregister()
function unregister(protocol): Promise<null>
取消註冊應用程式作為指定協定的預設處理程序。
參數
參數 | 類型 | 描述 |
---|---|---|
protocol | string | 協定的名稱,不包含 :// 。 |
回傳
Promise
<null
>
範例
import { unregister } from '@tauri-apps/plugin-deep-link';await unregister("my-scheme");
- macOS / Linux / Android / iOS:不支援。
自從
2.0.0
來源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L61
© 2025 Tauri Contributors。CC-BY / MIT