Member-only story
🚀 “The Power of Linking in React Native: Open Apps, Websites & More”
2 min read 1 day ago
In this guide we will talk about the power of Linking Api in React Native. It is used to handle deep linking
, open external URL’s
, navigate to app settings
, initiate phone calls
and send emails
etc.
🚀 Importing Linking
To use the Linking
API, you need to import it from React Native:
import { Linking } from 'react-native';
🚀 Opening External Links
You can use the openURL()
method to open a link in the default browser.
const openWebsite = () => {
Linking.openURL('https://www.google.com');
};
🚀 Checking If a URL Can Be Opened
Before opening a URL, you can check if it is supported using canOpenURL()
.
const openUrlSafely = async (url: string) => {
const supported = await Linking.canOpenURL(url);
if (supported) {
await Linking.openURL(url);
} else {
console.log(`Cannot open URL: ${url}`);
}
};
🚀 Opening Specific Apps
You can open apps like dialer, email, WhatsApp, etc. by using specific URL schemes.