LynxLinking
Opens links outside the app, in the browser, in another app, or in a browser sheet over the app, opens the app's own page in the phone's Settings, 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.
Set it up in angular.json
Opening links needs no setup. Three options in the build target decide which links open the app, and which apps it can ask about:
ng build --platform builds them into the apps. Open the app from a link covers the files your site serves for appLinkDomains.
Usage
API
LynxLinking
Links to the app arrive only in the apps --platform builds (ng build or ng serve), from a scheme in angular.json's deepLinkSchemes, or a domain in its appLinkDomains.
- In the web preview and Lynx Explorer,
getInitialURL()isnulland noonURL()handler is called. - In unit tests, the testing library's
render()starts the app with one (itsinitialURLoption).openLink()sends one while it's open.
LynxLinking.openURL()
Opens url where the system opens it:
httpandhttps: the default browsermailto:: the mail apptel:: the phone- another app's own scheme: that app
An http(s) link that an installed app claims opens that app. It claims it through a universal link on iOS or an App Link on Android.
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()
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
TypeErrorfor any other scheme, which the sheets can't show. UseopenURL()for those. - a
LinkingErrorwhen 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()
Resolves whether something on the device opens url.
- iOS answers only for the schemes the app declares.
- Android 11 and later answer 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.openAppSettings()
Opens the app's own page in the phone's Settings, where the person can allow a permission they refused: Bluetooth, the camera, the photo library, notifications, their location. Once the system stops asking for a permission, only Settings can change it, so an app's usual answer is a button that opens this page. iOS stops after one refusal, and Android 11 and later after two. A service's denied or unauthorized reads the same after Android's first refusal, while the system still asks once more, so ask again with its requestPermission() before offering Settings. It's React Native's Linking.openSettings().
- iOS: the app's page in Settings, which lists the permissions it asked for.
- Android: the app's App info page, whose Permissions entry lists them.
Resolves once Settings is opening, not when the person comes back. You don't need to wait for that: the services that read a permission, such as LynxBluetooth.state() and LynxGeolocation.state(), read it again as the app returns to the front, so the screen moves on by itself. iOS ends an app when the person changes some of its permissions, such as the camera's, and it then starts again with the new answer.
Rejects with a LinkingError: unavailable in the web preview and Lynx Explorer, which have no such page, and failed when Settings doesn't open.
LynxLinking.getInitialURL()
The link that started the app, such as myapp://orders/42. It's null when the person started it another way, from its icon for instance.
- It stays the same for as long as the app runs.
- It answers at once, because the app is given the link before it starts. React Native's
Linking.getInitialURL()is asynchronous. - With
provideRouter(), the router's first screen is already the link's route.
LynxLinking.onURL()
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
injectorto 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
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.
