HomeGuidesReferenceLearn

Reference version

ArchiveExpo SnackDiscord and ForumsNewsletter
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 51).

Expo Linking

GitHub

npm

An API that provides methods to create and open deep links universally.

Android
iOS
tvOS
Web

expo-linking provides utilities for your app to interact with other installed apps using deep links. It also provides helper methods for constructing and parsing deep links into your app. This module is an extension of the React Native Linking module.

For a more comprehensive explanation of how to use expo-linking, refer to the Linking guide.

Installation

Terminal
- npx expo install expo-linking

If you are installing this in an existing React Native app (bare workflow), start by installing expo in your project. Then, follow the additional instructions as mentioned by library's README under "Installation in bare React Native projects" section.

API

import * as Linking from 'expo-linking';

Hooks

Android
iOS
tvOS
Web

useLinkingURL()

Returns the linking URL followed by any subsequent changes to the URL. Always returns the initial URL immediately on reload.

Returns:

string | null

Returns the initial URL or null.

Android
iOS
tvOS
Web

useURL()

Returns the initial URL followed by any subsequent changes to the URL.

Returns:

string | null

Returns the initial URL or null.

Methods

Android
iOS
tvOS
Web

Linking.canOpenURL(url)

NameTypeDescription
urlstring

The URL that you want to test can be opened.


Determine whether or not an installed app can handle a given URL. On web this always returns true because there is no API for detecting what URLs can be opened.

Returns:

Promise<boolean>

A Promise object that is fulfilled with true if the URL can be handled, otherwise it false if not.

The Promise will reject on Android if it was impossible to check if the URL can be opened, and on iOS if you didn't add the specific scheme in the LSApplicationQueriesSchemes key inside Info.plist.

Android
iOS
tvOS
Web

Linking.collectManifestSchemes()

Collect a list of platform schemes from the manifest.

This method is based on the Scheme modules from @expo/config-plugins which are used for collecting the schemes before prebuilding a native app.

  • iOS: scheme -> ios.scheme -> ios.bundleIdentifier
  • Android: scheme -> android.scheme -> android.package
Returns:

string[]

Android
iOS
tvOS
Web

Linking.createURL(path, namedParameters)

NameTypeDescription
pathstring

Addition path components to append to the base URL.

namedParameters
(optional)
CreateURLOptions

Additional options object.

Default: {}

Helper method for constructing a deep link into your app, given an optional path and set of query parameters. Creates a URI scheme with two slashes by default.

The scheme must be defined in the Expo config (app.config.js or app.json) under expo.scheme or expo.{android,ios}.scheme. Platform-specific schemes defined under expo.{android,ios}.scheme take precedence over universal schemes defined under expo.scheme.

Examples

  • Development and production builds: <scheme>://path - uses the optional scheme property if provided, and otherwise uses the first scheme defined by your Expo config
  • Web (dev): https://localhost:19006/path
  • Web (prod): https://myapp.com/path
  • Expo Go (dev): exp://128.0.0.1:8081/--/path

The behavior of this method in Expo Go for published updates is undefined and should not be relied upon. The created URL in this case is neither stable nor predictable during the lifetime of the app. If a stable URL is needed, for example in authorization callbacks, a build (or development build) of your application should be used and the scheme provided.

Returns:

string

A URL string which points to your app with the given deep link information.

Android
iOS
tvOS
Web

Linking.getInitialURL()

Get the URL that was used to launch the app if it was launched by a link.

Returns:

Promise<string | null>

The URL string that launched your app, or null.

Android
iOS
tvOS
Web

Linking.getLinkingURL()

Get the URL that was used to launch the app if it was launched by a link.

Returns:

string | null

The URL string that launched your app, or null.

Android
iOS
tvOS
Web

Linking.hasConstantsManifest()

Ensure the user has linked the expo-constants manifest in bare workflow.

Returns:

boolean

Android
iOS
tvOS
Web

Linking.hasCustomScheme()

Returns:

boolean

Android
iOS
tvOS
Web

Linking.openSettings()

Open the operating system settings app and displays the app’s custom settings, if it has any.

Returns:

Promise<void>

Android
iOS
tvOS
Web

Linking.openURL(url)

NameTypeDescription
urlstring

A URL for the operating system to open, eg: tel:5555555, exp://.


Attempt to open the given URL with an installed app. See the Linking guide for more information.

Returns:

Promise<true>

A Promise that is fulfilled with true if the link is opened operating system automatically or the user confirms the prompt to open the link. The Promise rejects if there are no applications registered for the URL or the user cancels the dialog.

Android
iOS
tvOS
Web

Linking.parse(url)

NameTypeDescription
urlstring

A URL that points to the currently running experience (e.g. an output of Linking.createURL()).


Helper method for parsing out deep link information from a URL.

Returns:

ParsedURL

A ParsedURL object.

Android
iOS
tvOS
Web

Linking.parseInitialURLAsync()

Helper method which wraps React Native's Linking.getInitialURL() in Linking.parse(). Parses the deep link information out of the URL used to open the experience initially. If no link opened the app, all the fields will be null.

On the web it parses the current window URL.

Returns:

Promise<ParsedURL>

A promise that resolves with ParsedURL object.

Android
iOS
tvOS
Web

Linking.resolveScheme(options)

NameType
options{ isSilent: boolean, scheme: string }

Returns:

string

Android

Linking.sendIntent(action, extras)

NameType
actionstring
extras
(optional)
SendIntentExtras[]

Launch an Android intent with extras.

Use IntentLauncher instead, sendIntent is only included in Linking for API compatibility with React Native's Linking API.

Returns:

Promise<void>

Event Subscriptions

Android
iOS
tvOS
Web

Linking.addEventListener(type, handler)

NameTypeDescription
type'url'

The only valid type is 'url'.

handlerURLListener

An URLListener function that takes an event object of the type EventType.


Add a handler to Linking changes by listening to the url event type and providing the handler. It is recommended to use the useURL() hook instead.

Returns:

EmitterSubscription

An EmitterSubscription that has the remove method from EventSubscription

Types

Android
iOS
tvOS
Web

CreateURLOptions

NameTypeDescription
isTripleSlashed
(optional)
boolean

Should the URI be triple slashed scheme:///path or double slashed scheme://path.

queryParams
(optional)
QueryParams

An object of parameters that will be converted into a query string.

scheme
(optional)
string

URI protocol <scheme>:// that must be built into your native app.

Android
iOS
tvOS
Web

EventType

NameTypeDescription
nativeEvent
(optional)
MessageEvent-
urlstring-
Android
iOS
tvOS
Web

NativeURLListener()

NameType
nativeEventMessageEvent
Android
iOS
tvOS
Web

ParsedURL

NameTypeDescription
hostnamestring | null-
pathstring | null

The path into the app specified by the URL.

queryParamsQueryParams | null

The set of query parameters specified by the query string of the url used to open the app.

schemestring | null-
Android
iOS
tvOS
Web

QueryParams

Type: Record<string, undefined | string | string[]>

Android
iOS
tvOS
Web

SendIntentExtras

NameTypeDescription
keystring-
valuestring | number | boolean-
Android
iOS
tvOS
Web

URLListener()

NameType
eventEventType