For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/deep-links.md.

Open the app from a link

A deep link is a link that opens your app on a screen: tickets://events/jazz-night in a message, an email or a QR code opens the Tickets app on Jazz Night. You give the app a URL scheme in angular.json, and the router does the rest. A link opens the app on its route whether the app was closed or already open.

Nothing on the web opens an app's scheme, so links only arrive in the app ng build --platform or ng serve --platform makes. See Try it.

Give the app a scheme

List the schemes that open the app in deepLinkSchemes, in the build target's options:

angular.json
"build": {
  "builder": "@blotch/angular-lynx-build:application",
  "options": {
    "appName": "Tickets",
    "deepLinkSchemes": ["tickets"]
  }
}

ng build --platform registers each one with the phone: as a URL type in Info.plist on iOS, and as an intent filter on the app's activity on Android. Pick a scheme no other app is likely to use, such as your app's name. When two apps claim one, the phone picks either.

With provideRouter() from @blotch/angular-lynx, a link navigates to its route by itself, as Expo Router does:

LinkRoute
tickets://events/jazz-night/events/jazz-night
tickets://events/jazz-night?seat=4/events/jazz-night?seat=4
tickets:///events/jazz-night/events/jazz-night
tickets:///

Everything after tickets:// is the route, the first part too: in tickets://events/jazz-night, events is what a URL parser calls the host. The query and the fragment come along, so withComponentInputBinding() hands a component both the route's parameters and the query's:

src/app/app.routes.ts
export const routes: Routes = [
  { path: '', component: Events },
  { path: 'events/:id', component: EventDetail },
];
src/app/event-detail.ts
export class EventDetail {
  readonly id = input.required<string>(); // jazz-night
  readonly seat = input<string>(); // 4
}
  • A link that starts the app makes its route the first screen, as an address does when you open a page in a browser. The app doesn't draw the home screen first, and there's nothing under the link's screen: back leaves the app, as it does from any first screen.
  • A link while the app is open, in front or in the background, navigates there from wherever the app is, as a routerLink does. Back goes to where the person was.
  • A link no route matches leaves the app where it is. If it started the app, the app starts at / instead, and logs a warning that names the link. Add a ** route to show a page of your own for these.

Guards, resolvers and redirects run as for any navigation, so a link to a screen behind sign-in goes to your sign-in page if the guard sends it there.

A scheme only works where the phone already knows the app is installed. Links in email, chat and search results are https:// links, and a scheme link has no website to fall back to. To have your own site's links open the app, list its domains in appLinkDomains:

angular.json
"options": {
  "appName": "Tickets",
  "appId": "com.example.tickets",
  "deepLinkSchemes": ["tickets"],
  "appLinkDomains": ["tickets.example.com"],
  "ios": { "teamId": "ABCDE12345" }
}

https://tickets.example.com/events/jazz-night then opens the app on /events/jazz-night, the route after the host, the same as tickets://events/jazz-night. Where the app isn't installed, the link opens the website as before. *.example.com covers every subdomain of example.com. These are Universal Links on iOS and App Links on Android:

  • iOS gets the Associated Domains entitlement. Signing it takes a team in the paid Apple Developer Program: a free Personal Team can't, so --run --device fails with one, and says so.
  • Android gets an intent filter that Android verifies when the app is installed. Android 12 and later open a domain's links in the browser until it's verified.

The phone only trusts the domain once the domain names the app. ng build --platform writes the file it reads beside the app, ready to upload:

PlatformFileNames the app by
iOSdist/ios/.well-known/apple-app-site-associationios.teamId and appId
Androiddist/android/.well-known/assetlinks.jsonappId and the SHA-256 fingerprint of the certificate that signed the app

Serve each one at that path on every domain (for *.example.com, on example.com), over https, as application/json and with no redirect. iOS fetches it through Apple's servers when the app is installed, so a change can take a day to reach phones. Without ios.teamId, the iOS file has TEAM_ID where the team goes. The Android build reads the fingerprint from the app with the Android SDK's apksigner. An app installed from Google Play is signed with Google's key instead of your upload key, so add that key's fingerprint too, from Play Console → Test and release → App integrity → App signing.

Every path on the domain opens the app. To leave some to the browser, narrow components in the iOS file on your site, or send those links back out with provideDeepLinkRoute() and LynxLinking.openURL().

To try one, install the app and open the link from Notes or Messages on an iPhone, or with adb on Android. adb shell pm verify-app-links --re-verify com.example.tickets checks the domain again after you upload the file.

adb shell am start -a android.intent.action.VIEW -d 'https://tickets.example.com/events/jazz-night'

To change where links lead, provide a function that gets each one and returns the route to go to, or null to stay where the app is. It's Expo Router's redirectSystemPath:

src/app/app.config.ts
import { provideDeepLinkRoute, provideRouter } from '@blotch/angular-lynx';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideDeepLinkRoute(({ url, route, initial }) => {
      // Links from before the screen was renamed.
      if (route.startsWith('/shows/'))
        return route.replace('/shows/', '/events/');
      // A link the app handles itself, below.
      if (url.startsWith('tickets://invite')) return null;
      return route;
    }),
  ],
};

It gets the whole url, the route it would go to, and whether the link is the one that started the app (initial). For a link that started the app, null starts it at /.

Read the URL yourself

For a link that isn't a screen, such as an invitation to accept, read the URL with LynxLinking, the same service that opens links out of the app:

src/app/app.ts
export class App {
  readonly #linking = inject(LynxLinking);
  readonly #invites = inject(Invites);

  constructor() {
    // The link that started the app, or null.
    const first = this.#linking.getInitialURL();
    if (first) this.#accept(first);

    // Each link that arrives while the app is open.
    this.#linking.onURL((url) => this.#accept(url));
  }

  #accept(url: string): void {
    if (url.startsWith('tickets://invite')) this.#invites.accept(url);
  }
}

They're React Native's Linking.getInitialURL() and url event. getInitialURL() answers straight away, since the app is given the link before it starts, and stays the same for as long as the app runs. onURL() never gets that first link. A link that arrives while the app is still starting waits for the first onURL() handler, so none is lost. A handler registered in a constructor goes when its component or service is destroyed, and onURL() returns a function that removes it sooner.

Both work without the router too. With it, the router still navigates: return null from provideDeepLinkRoute() for the links you handle yourself.

Try it

Links need the real app, so run it with --platform, then open a link from your computer:

ng build --platform ios --run
xcrun simctl openurl booted 'tickets://events/jazz-night?seat=4'

ng build --platform android --run
adb shell am start -a android.intent.action.VIEW -d 'tickets://events/jazz-night?seat=4'

The Simulator may ask "Open in Tickets?" before handing the link over. Run the command with the app closed to see a link start it, and again with it open. On a phone, send yourself the link in a message, or open it from a QR code. After changing deepLinkSchemes, build the app again: the schemes are compiled into it.

In the web preview, Lynx Explorer and tests

  • In the web preview and in Lynx Explorer, no link ever opens the app: getInitialURL() is null, and onURL() handlers aren't called. The router starts at /.
  • In unit tests, start the app with a link with the testing library's render() option initialURL, and send one while it's open with openLink(). Then check where it went:
src/app/app.test.ts
import {
  openLink,
  render,
  screen,
  waitForUpdate,
} from '@blotch/angular-lynx-testing-library';

it('starts at the event the link opens', async () => {
  await render(App, {
    providers: [provideRouter(routes)],
    initialURL: 'tickets://events/jazz-night',
  });
  await waitForUpdate();

  expect(screen.getByText('Jazz Night')).toBeInTheDocument();
});

it('shows the event a link opens while the app is open', async () => {
  await render(App, { providers: [provideRouter(routes)] });

  openLink('tickets://events/jazz-night');
  await waitForUpdate();

  expect(screen.getByText('Jazz Night')).toBeInTheDocument();
});