Skip to main content

Usage Patterns

Choose from three flexible integration patterns: Singleton, Hook, or Provider. Select the one that best fits your app's architecture and complexity.

This documentation covers @apliko/react-native-deep-link 0.3.0.

The link that opened your app (and a deferred link) is delivered once. It goes to the first listener you register (or to the first getInitialUrl() / getInitialUrlAsync() call), and other listeners don't receive it. Links that arrive while the app is running go to every listener. Links are always delivered in the order they were opened. For predictable behavior, register one listener at startup (in your entry file, or an AplikoLinkProvider at the root) and navigate there. A screen that mounts later reads the latest link with AplikoLink.getCurrentLink(): it is never used up and makes no extra request. If both a startup listener and a screen listener navigate on links, act in only one of them.

Each callback receives the url exactly as the device opened it, a data object with the link's details from Apliko Link, and a meta object telling you how the link arrived. data is an empty object if the details could not be loaded (for example when the device is offline) and for any link that is not an Apliko link on your *.nvgt.link subdomain, such as custom-scheme links. If the details can't be loaded in time, the SDK still delivers the link, with an empty data object.

Singleton API: AplikoLink

Best for complex apps that manually manage subscription lifecycles, need fine-grained control, or for use inside testing environments.

typescript
import { AplikoLink } from '@apliko/react-native-deep-link';

// Subscribe to deep link events, including the link that launched the app (if any)
const unsubscribe = AplikoLink.addListener((url, data, meta) => {
  console.log('Received deep link:', url, data, meta?.source);
});

// Later, unsubscribe to prevent memory leaks
unsubscribe();

Hook API: useAplikoLink (Recommended)

The recommended approach for most functional components. It's clean, automatically handles the subscription lifecycle (subscribing on mount and unsubscribing on unmount), and integrates seamlessly with React's architecture.

An inline callback is fine: the screen keeps one subscription for its lifetime, and each link is handled by the callback from the latest render. The link that opened the app goes to the first listener, so a hook in a screen that mounts later won't receive it: handle it in your startup listener, or read it with getCurrentLink().

Provider API: AplikoLinkProvider

Ideal for centralized, app-wide deep link handling. Wrap your root component with the provider to listen for links anywhere in your application without needing to use hooks in specific components.

tsx
import { AplikoLinkProvider, UrlSchemeMetaData, LinkEventMeta } from '@apliko/react-native-deep-link';

function handleLink(url: string | null, data?: UrlSchemeMetaData, meta?: LinkEventMeta) {
  // Handle all deep links globally from here
  console.log('Global deep link:', url, data, meta?.source);
}

function App() {
  return (
    <AplikoLinkProvider onLink={handleLink}>
      {/* Your App's Component Tree */}
    </AplikoLinkProvider>
  );
}