Linking

Projects with Native Code Only

This section only applies to projects made with react-native init
or to those made with Create React Native App which have since ejected. For
more information about ejecting, please see
the guide on
the Create React Native App repository.

Linking gives you a general interface to interact with both incoming and outgoing app links.

Basic Usage

Handling deep links

If your app was launched from an external url registered to your app you can access and handle it from any component you want with

If you wish to receive the intent in an existing instance of MainActivity, you may set the launchMode of MainActivity to singleTask in AndroidManifest.xml. See <activity> documentation for more information.

NOTE: On iOS, you'll need to link RCTLinking to your project by following the steps described here. If you also want to listen to incoming app links during your app's execution, you'll need to add the following lines to your *AppDelegate.m:

The method returns a Promise object. If the user confirms the open dialog or the url automatically opens, the promise is resolved. If the user cancels the open dialog or there are no registered applications for the url, the promise is rejected.

This method will fail if the system doesn't know how to open the specified URL. If you're passing in a non-http(s) URL, it's best to check {@code canOpenURL} first.

For web URLs, the protocol ("http://", "https://") must be set accordingly!

canOpenURL()

canOpenURL(url);

Determine whether or not an installed app can handle a given URL.

For web URLs, the protocol ("http://", "https://") must be set accordingly!

As of iOS 9, your app needs to provide the LSApplicationQueriesSchemes key inside Info.plist or canOpenURL will always return false.

Parameters:

Name

Type

Required

Description

url

string

Yes

The URL to open

getInitialURL()

getInitialURL();

If the app launch was triggered by an app link, it will give the link url, otherwise it will give null