In this lesson, you will learn how your React Native app captures "external intents" from the mobile operating system to route users directly to specific content.
Bridging the OS Intent System
Think of your app as a house. Normally, a user enters through the front door (the app icon). But sometimes, you want to send someone a digital "key" that lets them walk directly into the kitchen or the bedroom without wandering through the hallway. This is what we call Deep Linking.
When a user clicks a link (like myapp://profile/123) in an email or a website, the mobile OS triggers an Intent. Because React Native sits atop the native layer, it needs a way to bridge this OS-level signal into your JavaScript environment.
Bridging the Gap
When the OS receives that link, it checks its registry to see which app should handle it. If it’s your app, the OS pushes the URL into your application’s memory. Your job is to "listen" for this event using the native bridge.
Here is how you handle that incoming event:
import { useEffect } from 'react';
import { Linking } from 'react-native';
const App = () => {
useEffect(() => {
// We set up a listener to catch the OS "intent"
const subscription = Linking.addEventListener('url', ({ url }) => {
console.log('App opened via intent:', url);
// Here, you would parse the URL and navigate
// the user to the specific screen requested.
});
return () => subscription.remove();
}, []);
return null; // Your UI code here
};
The Role of App State
Deep linking is often tied to App State. When an intent arrives, your app might be in the background, or it might be completely closed. The "Deep Linking and App State" integration ensures that whether the app is waking up from a terminated state or just shifting from the background, the native layer persists the URL data long enough for your JavaScript logic to read it and perform the navigation.
Key Takeaway: Deep linking is the process of using the OS intent system to capture external URL signals, allowing your app to bypass the home screen and land the user exactly where the link intended.