react-native-smartlink
v1.0.0
Published
Lightweight native deep linking SDK for React Native and Expo apps
Readme
React Native Smartlink
A lightweight native deep linking SDK for React Native and Expo apps. Uses React Native's built-in Linking module—no Expo Linking dependency required.
Works with React Native CLI projects and Expo projects using Expo Dev Client or Expo prebuild.
Features
- Native Linking – Uses
react-native'sLinkingAPI - Custom URL Schemes –
myapp://product?id=10 - Universal Links –
https://myapp.link/product?id=10 - Zero Expo Dependencies – Works in bare React Native
- CLI Setup – One command to configure your project
Installation
npm install react-native-smartlinkor
yarn add react-native-smartlinkQuick Start
1. Run the setup CLI
npx react-native-smartlink initThe CLI will ask you:
- App domain – e.g.,
https://myapp.link - App scheme – e.g.,
myapp - Universal links –
yesorno
This creates smartlink.config.json and configures your project.
Non-interactive mode (for CI/scripts):
npx react-native-smartlink init --domain https://myapp.link --scheme myapp --universal-links2. Configure in your app
In your root App.tsx or entry point:
import { configure, listenLink, getInitialLink } from 'react-native-smartlink';
import config from './smartlink.config.json';
// Configure with your settings
configure(config);
// Listen for deep links when app is open
listenLink((data) => {
console.log('Deep link received:', data);
// { path: 'product', params: { id: '10' } }
});
// Handle initial link (app launched from closed state)
getInitialLink().then((link) => {
if (link) {
console.log('App opened with:', link);
}
});3. Create deep links
import { createLink } from 'react-native-smartlink';
const url = createLink('product', { id: 10 });
// => "myapp://product?id=10"Configuration
smartlink.config.json
Created by the CLI. Example:
{
"domain": "https://myapp.link",
"scheme": "myapp",
"universalLinks": true
}| Field | Description |
|-------|-------------|
| domain | Your app domain for universal links |
| scheme | Custom URL scheme (e.g., myapp → myapp://) |
| universalLinks | Enable HTTPS universal links |
API Reference
configure(config)
Set configuration at runtime. Call once at app startup.
import { configure } from 'react-native-smartlink';
import config from './smartlink.config.json';
configure(config);createLink(path, params?)
Creates a deep link URL.
createLink('product', { id: 10 });
// => "myapp://product?id=10"
createLink('user/profile', { userId: '123' });
// => "myapp://user/profile?userId=123"
createLink('home');
// => "myapp://home"listenLink(callback)
Listens for deep links when the app is already open. Returns an unsubscribe function.
const unsubscribe = listenLink((data) => {
console.log(data); // { path: 'product', params: { id: '10' } }
});
// Later: unsubscribe();getInitialLink()
Returns the deep link that launched the app (cold start). Resolves to null if the app wasn't opened via a deep link.
const link = await getInitialLink();
if (link) {
console.log(link); // { path: 'product', params: { id: '10' } }
}parseLink(url)
Parses a URL string into structured data.
parseLink('myapp://product?id=10');
// => { path: 'product', params: { id: '10' } }getConfig()
Returns the current configuration.
const config = getConfig();
// => { domain: '...', scheme: '...', universalLinks: true }Platform Setup
Android
The CLI automatically adds intent filters to AndroidManifest.xml for:
- Custom scheme:
myapp:// - Universal links:
https://myapp.link/*
If you need to add them manually, add this inside your main <activity>:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="myapp" android:host=""/>
<data android:scheme="https" android:host="myapp.link" android:pathPrefix="/"/>
</intent-filter>iOS
Custom URL Scheme
The CLI updates app.json with expo.scheme for Expo projects. For Expo prebuild, run:
npx expo prebuildFor bare React Native, add the URL scheme in Xcode:
- Open the project in Xcode
- Select your target → Info tab
- Under URL Types, add a new entry
- Set Identifier and URL Schemes to your scheme (e.g.,
myapp)
Universal Links
- Create an
apple-app-site-associationfile on your domain:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "TEAM_ID.com.yourapp.bundle",
"paths": ["*"]
}
]
}
}Serve it at
https://myapp.link/.well-known/apple-app-site-associationIn Xcode, add Associated Domains:
applinks:myapp.linkFor Expo: add to
app.json:
{
"expo": {
"ios": {
"associatedDomains": ["applinks:myapp.link"]
}
}
}Expo Projects
- Run
npx react-native-smartlink init - Run
npx expo prebuildto regenerate native projects - Configure and use the SDK as shown above
Testing Deep Links
Android
adb shell am start -W -a android.intent.action.VIEW -d "myapp://product?id=10" com.yourappiOS Simulator
xcrun simctl openurl booted "myapp://product?id=10"License
MIT
