跳到内容
Tauri

@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: 此函数读取命令行参数,并检查是否只有一个值,该值必须是 URL,且 scheme 与配置的值之一匹配。

请注意,当使用 [Self::register] 动态注册深度链接 scheme 时,您必须手动检查参数。此外,深度链接可能作为 CLI 参数提供,因此您应该检查其格式是否与您期望的格式匹配。

始于

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L23


isRegistered()

function isRegistered(protocol): Promise<boolean>

检查应用是否是指定协议的默认处理程序。

参数

参数类型描述
protocolstring协议的名称,不带 ://

返回值

Promise<boolean>

示例

import { isRegistered } from '@tauri-apps/plugin-deep-link';
await isRegistered("my-scheme");

- macOS / Android / iOS: 不支持。

始于

2.0.0

Source: 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

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L99


register()

function register(protocol): Promise<null>

将应用注册为指定协议的默认处理程序。

参数

参数类型描述
protocolstring协议的名称,不带 ://。例如,如果您希望您的应用处理 tauri:// 链接,请使用 tauri 作为协议调用此方法。

返回值

Promise<null>

示例

import { register } from '@tauri-apps/plugin-deep-link';
await register("my-scheme");

- macOS / Android / iOS: 不支持。

始于

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L42


unregister()

function unregister(protocol): Promise<null>

取消注册应用作为指定协议的默认处理程序。

参数

参数类型描述
protocolstring协议的名称,不带 ://

返回值

Promise<null>

示例

import { unregister } from '@tauri-apps/plugin-deep-link';
await unregister("my-scheme");

- macOS / Linux / Android / iOS: 不支持。

始于

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/deep-link/guest-js/index.ts#L61


© 2025 Tauri 贡献者。CC-BY / MIT