Deep Linking
Set your Tauri application as the default handler for an URL.
Supported Platforms
- Windows
- Linux
- macOS
- Android
- iOS
Setup
This plugin requires a Rust version of at least 1.75
Install the deep-link plugin to get started.
Use your project’s package manager to add the dependency:
npm run tauri add deep-link
yarn run tauri add deep-link
pnpm tauri add deep-link
bun tauri add deep-link
cargo tauri add deep-link
-
Run the following command in the
src-tauri
folder to add the plugin to the project’s dependencies inCargo.toml
:cargo add tauri-plugin-deep-link@2.0.0-rc -
Modify
lib.rs
to initialize the plugin: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");} -
Install the JavaScript Guest bindings using your preferred JavaScript package manager:
npm install @tauri-apps/plugin-deep-linkyarn add @tauri-apps/plugin-deep-linkpnpm add @tauri-apps/plugin-deep-linkbun add @tauri-apps/plugin-deep-link
Setting up
Android
For app links, you need a server with a .well-known/assetlinks.json
endpoint that must return a text response in the given format:
[ { "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "$APP_BUNDLE_ID", "sha256_cert_fingerprints": [ $CERT_FINGERPRINT ] } }]
Where $APP_BUNDLE_ID
is the value defined on tauri.conf.json > identifier
with -
replaced with _
and $CERT_FINGERPRINT
is a list of SHA256 fingerprints of your app’s signing certificates, see verify android applinks for more information.
iOS
Server
For universal links, you need a server with a .well-known/apple-app-site-association
endpoint that must return a text response in the given format:
{ "applinks": { "details": [ { "appIDs": ["$DEVELOPMENT_TEAM_ID.$APP_BUNDLE_ID"], "components": [ { "/": "/open/*", "comment": "Matches any URL whose path starts with /open/" } ] } ] }}
Where $DEVELOPMENT_TEAM_ID
is the value defined on tauri.conf.json > tauri > bundle > iOS > developmentTeam
or the TAURI_APPLE_DEVELOPMENT_TEAM
environment variable and $APP_BUNDLE_ID
is the value defined on tauri.conf.json > identifier
. See applinks.details for more information.
App
You also need to add the associated domains to your app’s entitlements
file:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>com.apple.developer.associated-domains</key> <array> <string>applinks:your.website.com</string> <string>applinks:nother.site.br</string> </array></dict></plist>
See supporting associated domains for more information.
Configuration
Under tauri.conf.json > plugins > deep-link
, configure the domains (mobile) and schemes (desktop) you want to associate with your application:
{ "plugins": { "deep-link": { "mobile": [ { "host": "your.website.com", "pathPrefix": ["/open"] }, { "host": "another.site.br" } ], "desktop": { "schemes": ["something", "my-tauri-app"] } } }}
Usage
The deep-link plugin is available in both JavaScript and Rust.
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';// when using `"withGlobalTauri": true`, you may use// const { onOpenUrl } = window.__TAURI_PLUGIN_DEEP_LINK__;
await onOpenUrl((urls) => { console.log('deep link:', urls);});
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| { app.listen("deep-link://new-url", |url| { dbg!(url); }); Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}
Permissions
By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities
configuration to enable these.
See the Capabilities Overview for more information and the step by step guide to use plugin permissions.
{ "$schema": "../gen/schemas/mobile-schema.json", "identifier": "mobile-capability", "windows": ["main"], "platforms": ["iOS", "android"], "permissions": [ // Usually you will need event:default to listen to the deep-link event "event:default", "deep-link:default" ]}
Default Permission
Allows reading the opened deep link via the get_current command
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. |
© 2024 Tauri Contributors. CC-BY / MIT