@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
]。此外,深度链接可能已作为 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>
用于在应用程序运行期间触发协议时每次运行函数的辅助函数。使用 getCurrent
在应用程序加载时检查您的应用程序是否通过深度链接启动。
参数
参数 | 类型 |
---|---|
handler | (urls ) => void |
返回值
Promise
<UnlistenFn
>
示例
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';await onOpenUrl((urls) => { console.log(urls) });
- Windows / Linux:没有单实例插件不支持。操作系统将使用 CLI 参数传递 URL 创建新应用程序实例。
自从
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 贡献者。CC-BY / MIT