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

# Deep links

> Open your app at a route, react to links while it is open, and open other apps.

A deep link opens a mini app inside the shell (or brings it to the front), optionally at a route inside it:

```
xyz.cskn.apps://open/<slug>[/<path>][?<query>]     mobile
cskn-apps://open/<slug>[/<path>][?<query>]         desktop
```

For example, `xyz.cskn.apps://open/music/playlist/42?ref=share` opens the Music app at `/playlist/42?ref=share`.

## Following links in your router

`useDeepLink` starts with the link the app was launched with and updates whenever a new one arrives while the app is open. Drive your router from it:

```tsx theme={null}
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useDeepLink } from '@cskn/sdk';

function DeepLinkRouter() {
  const link = useDeepLink(); // { path, url, params } | null
  const navigate = useNavigate();

  useEffect(() => {
    if (link) navigate(link.path);
  }, [link, navigate]);

  return null;
}
```

A link reaches your app in one of two ways:

* **Launch link.** When a link opens the app, the path is already part of the URL the page boots with. No event is sent. Read it with `getInitialDeepLink()`.
* **Runtime link.** When the app is already open, the shell sends a `deeplink` event so your router can navigate without reloading. Subscribe with `onDeepLink(cb)`.

```ts theme={null}
import { getInitialDeepLink, onDeepLink } from '@cskn/sdk';

const initial = await getInitialDeepLink();           // { path, url, params } | null
const unsubscribe = onDeepLink(({ path }) => router.navigate(path));
```

## Opening another app

```ts theme={null}
import { openDeepLink } from '@cskn/sdk';

openDeepLink({ slug: 'store', path: '/product/9' });        // another app: user confirms
openDeepLink({ url: 'https://store.cskn.app/product/9' });   // same, by URL
openDeepLink({ path: '/settings' });                         // inside this app: no prompt
```

<ParamField path="slug" type="string">Another app to open or bring to the front.</ParamField>
<ParamField path="url" type="string">A full `cskn.app` URL instead of a slug.</ParamField>
<ParamField path="path" type="string">The route to open. Alone, it navigates inside the current app.</ParamField>
<ParamField path="params" type="Record<string, string>">Query parameters.</ParamField>

<Note>
  Opening a **different** app always shows the user a confirmation ("X wants to open Y"). Nothing happens if they decline, so an app cannot move the user to another app without their consent. Navigating within your own app needs no confirmation.
</Note>

## Surfaces

| Surface | Behavior |
| - | - |
| Mobile, desktop | Full support, from the OS and from other apps. |
| TV | App-to-app links through the SDK. OS launch links are not supported yet. |
| Browser | `getInitialDeepLink` and `useDeepLink` return the current location; `openDeepLink` does a normal navigation. The same code works on a user page. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.