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 /api/angular-lynx/linking.md.

LynxLinking

Opens links outside the app, in the browser, in another app, or in a browser sheet over the app, and hears the links that open this one. import { LynxLinking, LinkingError, type OpenInAppOptions, type LinkingErrorCode, type LynxLinkHandler } from '@blotch/angular-lynx';

Open links outside the app and Open the app from a link show it in use.

Usage

const linking = inject(LynxLinking);

await linking.openInApp('https://example.com/help');
await linking.openURL('mailto:support@example.com');
const hasWhatsApp = await linking.canOpenURL('whatsapp://send');

const startedWith = linking.getInitialURL(); // 'myapp://orders/42', or null
linking.onURL((url) => console.log('Opened with', url));

API

LynxLinking

@Injectable({ providedIn: 'root' })
class LynxLinking {}
HostopenURL()openInApp()canOpenURL()
iOS (ng build --platform ios)UIApplication.openSFSafariViewControllerUIApplication.canOpenURL
Android (ng build --platform android)An ACTION_VIEW intentA Custom TabresolveActivity
Web previewA new tabA new tabtrue
Lynx ExplorerRejects with unavailableRejects with unavailablefalse
Unit tests (testing library)Records the URLRecords the URLtrue

Links to the app arrive only in the apps --platform builds (ng build or ng serve), from a scheme in angular.json's deepLinkSchemes. In the web preview and Lynx Explorer, getInitialURL() is null and no onURL() handler is called; in unit tests, the testing library's render() starts the app with one (its initialURL option), and openLink() sends one while it's open.

LynxLinking.openURL()

openURL(url: string): Promise<void>;

Opens url where the system opens it: the default browser for http and https, the mail app for mailto:, the phone for tel:, and another app for its own scheme. An http(s) link that an installed app claims, through a universal link on iOS or an App Link on Android, opens that app. Resolves once the URL is handed over. Rejects with a LinkingError when nothing on the device opens it, and with a TypeError when url isn't absolute.

LynxLinking.openInApp()

openInApp(url: string, options?: OpenInAppOptions): Promise<void>;

Opens an http or https url in a browser sheet over the app, so the person comes straight back to where they were. Resolves once they're back in the app:

  • iOS: when they close the sheet.
  • Android: when the app comes back to the front. Android doesn't say when a Custom Tab closes, so this is the closest it can tell: the person closed the tab, or switched back to the app another way, which leaves the tab behind it.
  • Web: when they close the tab or come back to the app's tab.

Rejects with a TypeError for any other scheme, which the sheets can't show (use openURL() for those), and with a LinkingError when the sheet can't open, such as while another is open.

The sheet keeps its own cookies on iOS, apart from Safari's. On Android it shares the browser's. To sign in through a page and get a result back, use LynxWebAuthSession instead.

LynxLinking.canOpenURL()

canOpenURL(url: string): Promise<boolean>;

Resolves whether something on the device opens url. iOS answers only for the schemes the app declares, and Android 11 and later only for the apps the app says it looks for, so list the schemes you ask about in canOpenURLSchemes in angular.json. http, https, mailto, tel and sms are always declared. For any other scheme, the answer is false.

LynxLinking.getInitialURL()

getInitialURL(): string | null;

The link that started the app, such as myapp://orders/42, or null when the person started it another way, from its icon for instance. It stays the same for as long as the app runs. React Native's Linking.getInitialURL() is asynchronous; this answers at once, because the app is given the link before it starts. With provideRouter(), the router's first screen is already the link's route.

LynxLinking.onURL()

onURL(
  handler: LynxLinkHandler,
  options?: { readonly injector?: Injector },
): () => void;

type LynxLinkHandler = (url: string) => void;

Calls handler with each link that opens the app while it's running, in front or in the background, as React Native's url event does. The link that started the app isn't one of them: read it with getInitialURL(). Links that arrived while the app was still starting wait for the first handler. Called from an injection context, such as a constructor, the handler is removed when its component or service is destroyed; pass injector to tie it to another one. The function it returns removes it sooner. A handler's error goes to the app's ErrorHandler, and the other handlers are still called.

With provideRouter(), the router navigates to each link's route as well; provideDeepLinkRoute() changes that.

OpenInAppOptions

type OpenInAppOptions = {
  readonly toolbarColor?: string;
  readonly controlsColor?: string;
};
OptionDescription
toolbarColorThe color of the sheet's toolbar. On Android, the tab picks its icons' color to contrast with it
controlsColorThe color of the sheet's buttons. iOS only

Colors are hex (#1e3a8a, #1e3a8a80, #fff) or rgb()/rgba() with commas. Anything else rejects with a TypeError. iOS 27 draws Safari's own glass buttons over the page and leaves both colors out; earlier versions use them.

LinkingError

class LinkingError extends Error {
  readonly code: LinkingErrorCode;
}

type LinkingErrorCode = 'unavailable' | 'failed';
codeWhen
unavailableThe host can't open links. Only the apps --platform builds (ng build or ng serve) can
failedNothing on the device opens the URL, a browser sheet was already open, or the browser blocked the new tab