Routing
The router setup that lets Angular Router run on Lynx, deep-link routing, and the directive that marks the active link for screen readers. import { provideRouter, provideDeepLinkRoute, type DeepLink, type DeepLinkRoute, LynxRouterLinkActive } from '@blotch/angular-lynx';
The rest of the routing exports have pages of their own:
Usage
- Import
provideRouterfrom@blotch/angular-lynx, not@angular/router. - Everything else still comes from
@angular/router:RouterOutlet,RouterLink,RouterLinkActive,Router,ActivatedRouteand the rest. RouterLinkworks on any Lynx element. AngularLynx delivers a tap to itsclicklistener.
API
provideRouter()
Calls Angular's provideRouter() with your routes and features, and adds the Lynx pieces:
- Leaving a route destroys its components, as on the web.
provideRouter()keeps Angular's ownRouteReuseStrategy. To keep route views alive instead, provideLynxRouteReuseStrategy. - Failed navigations resolve to
falseinstead of rejecting. WatchRouter.eventsforNavigationErrorto detect them. - Your own
withRouterConfig()replaces this one, so includeresolveNavigationPromiseOnError: truein it. - From an event handler, call
router.navigate()directly, as on the web. - It tells
LynxRouterLinkActivewhere to find an element'sRouterLinkActive, soLYNX_ELEMENTSdoesn't import the router itself. WithoutprovideRouter(), active links don't get theselectedtrait.
Shortcuts
A shortcut with a route navigates there when the person runs it, from Siri or the app icon's menu. provideRouter() starts LynxShortcuts with the app, so it takes no code.
Deep links
A deep link with one of angular.json's deepLinkSchemes navigates to its route: myapp://orders/42?tab=items goes to /orders/42?tab=items.
- A link that starts the app is its first route, with nothing before it in the history.
- If the router can't go there, such as when no route matches, the app starts at
/and logs a warning. - A link while the app is open navigates there from the current screen.
provideDeepLinkRoute()changes where links lead.
The Android back button
- It calls
Location.back()whileLynxLocationStrategy.canGoBack()istrue. - It leaves the app when
canGoBack()isfalse, unless something open on top takes it first (seeLynxBackButton). - It works in the Android app
ng build --platform androidmakes, and in your own app if it sends the same event. - With a
LocationStrategyof your own, the back button always leaves the app.
provideDeepLinkRoute()
Decides where the router goes for a link that opens the app, as Expo Router's redirectSystemPath does.
It's called with each link:
- Return a route to navigate to it.
- Return
nullto stay where the app is. For the link that started the app, that's/. - An error it throws goes to the app's
ErrorHandler, and the link goes nowhere.
route is the link's path with its query and fragment:
- For the app's own scheme, everything after
//is the path, the host too.myapp://orders/42andmyapp:///orders/42both lead to/orders/42. - For an
httporhttpslink, the path starts after the host.
LynxRouterLinkActive
Adds the selected accessibility trait to an element while Angular's RouterLinkActive on it says its route is active. It takes it away after, so screen readers know which link is the current one.
- It's part of
LYNX_ELEMENTS, so it's on everyrouterLinkActiveelement of a component that importsLYNX_ELEMENTSandRouterLinkActive. - It has no inputs or outputs of its own.
- It keeps the element's own traits.
accessibility-traits="button"readsbutton,selectedwhile the link is active, andbuttonagain after. A trait set later is merged the same way. - Android leaves the element's traits alone. It reads a single trait (
none,imageorbutton) and has no selected trait, so a list would only lose the element's own. - On a component's host, add it to
hostDirectivesnext toRouterLinkActive. Host directives don't match selectors, soLYNX_ELEMENTScan't add it there:
Types
The routing pages use these Angular types:
Routes,RouterFeatures,ActivatedRouteSnapshotandDetachedRouteHandlefrom@angular/routerLocationChangeListenerfrom@angular/commonSignalfrom@angular/core
Related
- Routing and navigation: routes, links, lazy loading and navigating from code.
- Stack Outlet, Tab Outlet and Location
- Accessibility:
accessibility-traitsand the other attributes. - Bootstrap
- Angular Router
