Code Reference

Linking

React Native · Reference cheat sheet

Linking

React Native · Reference cheat sheet


📋 Overview

Linking opens URLs (https, tel, mailto, custom schemes) and listens for deep links that open the app. Configure schemes in native projects / app.json. For navigation integration, use React Navigation linking config or Expo Router.

🔧 Core concepts

APIRole
openURLOpen external / custom URL
canOpenURLCheck handler (iOS LS queries)
getInitialURLCold-start link
addEventListener('url')Warm links
openSettingsApp settings

Universal Links / App Links need domain association files.

💡 Examples

import { Linking, Pressable, Text, Alert } from "react-native";

async function openSupport() {
  const url = "mailto:support@example.com?subject=Help";
  const ok = await Linking.canOpenURL(url);
  if (!ok) {
    Alert.alert("No mail app available");
    return;
  }
  await Linking.openURL(url);
}

export function SupportLink() {
  return (
    <Pressable onPress={openSupport}>
      <Text>Email support</Text>
    </Pressable>
  );
}

Listen for URLs:

import { useEffect } from "react";
import { Linking } from "react-native";

useEffect(() => {
  Linking.getInitialURL().then((url) => {
    if (url) handleUrl(url);
  });
  const sub = Linking.addEventListener("url", ({ url }) => handleUrl(url));
  return () => sub.remove();
}, []);

⚠️ Pitfalls

  • iOS canOpenURL requires declared schemes in LSApplicationQueriesSchemes.
  • Not handling both cold and warm start.
  • Custom scheme collisions with other apps.
  • Using Linking alone without mapping to navigation routes.

On this page