Deep Linking in React Native

Deep Linking in React Native

🔗 React Native (TypeScript) এ Deep Linking

Deep Linking ব্যবহার করে আপনার React Native অ্যাপের নির্দিষ্ট স্ক্রিন সরাসরি URL বা Notification থেকে ওপেন করা যায়।

📌 Deep Linking কী?

Deep Linking মানে হলো – একটি নির্দিষ্ট URL ব্যবহার করে মোবাইল অ্যাপের কোনো নির্দিষ্ট স্ক্রিন ওপেন করা।

উদাহরণ:

myapp://profile/101

👉 এই URL ক্লিক করলে অ্যাপ খুলে সরাসরি Profile Screen (ID: 101) দেখাবে

🎯 Deep Linking কেন ব্যবহার করবেন?

  • Push Notification থেকে নির্দিষ্ট স্ক্রিনে নেওয়া
  • Email / SMS লিংক থেকে অ্যাপ ওপেন করা
  • Marketing campaign
  • Password reset / Invite link
  • Better user experience

🗂️ File-based Navigation Structure (TypeScript)

app/
 ├── index.tsx
 ├── profile/
 │    └── [id].tsx
 ├── settings.tsx
      

এখানে [id].tsx হচ্ছে একটি dynamic route, যেটা Deep Linking এর জন্য খুব গুরুত্বপূর্ণ।

⚙️ Deep Linking Setup (React Navigation + TypeScript)

প্রথমে প্রয়োজনীয় প্যাকেজ ইনস্টল করুন:

npm install @react-navigation/native
expo install expo-linking
      

🔧 Linking Configuration (TypeScript)

import * as Linking from 'expo-linking';

export const linking = {
  prefixes: ['myapp://'],
  config: {
    screens: {
      index: '',
      profile: {
        path: 'profile/:id',
      },
      settings: 'settings',
    },
  },
};
      

✔ এখানে আমরা URL structure define করেছি

🧭 NavigationContainer এ Linking যোগ করা

import { NavigationContainer } from '@react-navigation/native';
import { linking } from './linking';

export default function App() {
  return (
    
      {/* Stack / Tabs */}
    
  );
}
      

👤 Profile Screen (Dynamic Route)

import { View, Text } from 'react-native';
import { useLocalSearchParams } from 'expo-router';

export default function Profile() {
  const { id } = useLocalSearchParams<{ id: string }>();

  return (
    
      Profile ID: {id}
    
  );
}
      

📱 Output কী হবে?

যদি URL হয়:

myapp://profile/45

👉 অ্যাপ ওপেন হবে 👉 Profile Screen render হবে 👉 Screen এ দেখাবে:

Profile ID: 45
        

🧪 Deep Linking Test করার উপায়

  • Android: adb shell am start -W -a android.intent.action.VIEW -d "myapp://profile/1"
  • Expo: npx expo start --scheme myapp
  • Browser address bar থেকেও URL test করা যায়

✅ Summary

  • Deep Linking অ্যাপকে আরও smart করে
  • Dynamic route ব্যবহার করে সহজে data pass করা যায়
  • Marketing + Notification এ খুব গুরুত্বপূর্ণ
  • TypeScript এর সাথে 100% compatible
👼 Quiz
/

লোড হচ্ছে...