> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pushbase.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Deep linking

> Route users to specific screens on tap

<Info>
  Prerequisite: To enable deep linking, you must define your app’s scheme in the
  `app.json` file.

  ```json app.json theme={null}
  {
    "expo": {
      // replace this with your app scheme
      "scheme": "myapp"
    }
  }
  ```
</Info>

The Pushbase SDK supports deep linking, provided that the route is defined according to your app’s navigation structure.

To navigate a user to a specific screen via a notification, include the target route in the notification payload. When deep linking is enabled, the SDK automatically handles routing the user to the specified screen upon interaction.

<img style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/pushbase/nkMYcoi9amrb3572/images/deep-linking-notification.png?fit=max&auto=format&n=nkMYcoi9amrb3572&q=85&s=be94fbeda9b6b38ebfae9b7135d1a09e" width="3422" height="1672" data-path="images/deep-linking-notification.png" />

To illustrate how deep linking works with the Pushbase SDK, consider a travel app that lists hotels across major U.S. cities.

Suppose the marketing team wants to send push notifications featuring city-specific discount codes. When a user taps on a notification, the app should automatically navigate to the targeted city and display a list of hotels specific to that location.

<img style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/pushbase/nkMYcoi9amrb3572/images/deep-linking-flow.png?fit=max&auto=format&n=nkMYcoi9amrb3572&q=85&s=bc5332f1c1aaf6b3a482416d31172be9" width="2396" height="1630" data-path="images/deep-linking-flow.png" />

To enable this deep linking behavior, the app’s file structure should be organized based on the navigation strategy being used— **Expo Router** or **React Navigation**. Each approach requires a different configuration to correctly handle and route deep link URLs to the targeted screen.

<Tabs>
  <Tab title="Expo Router">
    ```yaml Expo Router Project structure theme={null}
    .
    └── app/
        ├── _layout.tsx
        ├── destinations/
        │   └── [slug].tsx
        └── index.tsx
    ```

    <Note>
      `destinations/[slug]` is a dynamic route, where `slug` is a unique identifier
      representing each city's route.
    </Note>
  </Tab>

  <Tab title="React Navigation">
    ```yaml React Navigation Project structure theme={null}
    .
    ├── screens/
    │   ├── HomeScreen.tsx
    │   └── DestinationScreen.tsx
    └── App.tsx
    ```

    Screen route names and configurations in React Navigation are managed using a
    [Stack Navigator](https://reactnavigation.org/docs/stack-navigator/)

    ```jsx App.tsx theme={null}
    import { NavigationContainer } from "@react-navigation/native";
    import { createStackNavigator } from "@react-navigation/stack";

    const Stack = createStackNavigator();

    export default function App() {
      return (
        <NavigationContainer>
          <Stack.Navigator>
            <Stack.Screen name="Home" component={HomeScreen} />
            <Stack.Screen name="Destination" component={DestinationScreen} />
          </Stack.Navigator>
        </NavigationContainer>
      );
    }
    ```
  </Tab>
</Tabs>

## Defining deep links

A deep link to a specific destination screen should
follow this format:

<ul>
  <li>`destinations/san-francisco` - San Francisco</li>
  <li>`destinations/new-york-city` - New York City</li>
  <li>`destinations/miami` - Miami</li>
  <li>`destinations/washington-dc` - Washington DC</li>
</ul>

All deep links are configured and attached to notifications directly through the Pushbase dashboard.

**Create a deep link**

<img style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/pushbase/nkMYcoi9amrb3572/images/create-deep-link.png?fit=max&auto=format&n=nkMYcoi9amrb3572&q=85&s=f8bb477ef170110c6149d4f9620d6e2a" width="3440" height="1758" data-path="images/create-deep-link.png" />

**List of deep links**

<img style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/pushbase/nkMYcoi9amrb3572/images/list-deep-link.png?fit=max&auto=format&n=nkMYcoi9amrb3572&q=85&s=ac00e670ecc8751d5c44951facf1824a" width="3452" height="1704" data-path="images/list-deep-link.png" />

**Assign deep link to a notification**

<img style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/pushbase/nkMYcoi9amrb3572/images/deep-linking-notification.png?fit=max&auto=format&n=nkMYcoi9amrb3572&q=85&s=be94fbeda9b6b38ebfae9b7135d1a09e" width="3422" height="1672" data-path="images/deep-linking-notification.png" />

## Handle Deep Link Routing

<Tabs>
  <Tab title="Expo Router">
    With Expo Router, Pushbase SDK automatically handles deep link navigation when a user taps on a notification that includes an assigned deep link. No extra works needed.
  </Tab>

  <Tab title="React Navigation">
    React Navigation’s [linking configuration](https://reactnavigation.org/docs/navigation-container#linking) can be used to handle incoming deep links from push notifications.

    This involves mapping defined deep link routes to their corresponding screen route names within your navigation structure.

    <Info>
      **Prerequisite**: install `expo-linking` package.

      ```bash theme={null}
      npx expo install expo-linking
      ```
    </Info>

    ```js theme={null}
    import { NavigationContainer } from "@react-navigation/native";
    import { createStackNavigator } from "@react-navigation/stack";
    import * as Linking from "expo-linking";

    const Stack = createStackNavigator();

    /* Map deep linking route to screen name.*/
    const config = {
      screens: {
        // The slug value will be replaced by city value like san-francisco or miami.
        Destination: "destinations/:slug",
      },
    };
    const linking = {
      prefixes: [prefix],
      config,
    };

    export default function App() {
      return (
        <NavigationContainer linking={linking}>
          <Stack.Navigator>
            <Stack.Screen name="Home" component={HomeScreen} />
            <Stack.Screen name="Destination" component={DestinationScreen} />
          </Stack.Navigator>
        </NavigationContainer>
      );
    }
    ```

    <Note>
      The reason that is necessary to use `Linking.createURL` is that the scheme
      will differ depending on whether you're in the client app or in a standalone
      app
    </Note>
  </Tab>
</Tabs>

<Tip>
  Having trouble setting up or configuring the SDK? Our support team is here to
  help — [feel free to reach
  out](mailto:hello@pushbase.dev?subject=Pushbase%20Product%20Support)
</Tip>
