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/routing/index.md.

Routing and navigation

Move between screens with Angular's Router, <router-outlet> and routerLink, as on the web.

What differs:

  • The URL lives in memory. There's no address bar.
  • A link is any element you tap.
  • The active link tells screen readers it's selected.

For screens that slide in and out, or tabs that stay alive, see Slide screens in and out and Keep each tab alive.

Set up the router

Import provideRouter() from @blotch/angular-lynx instead of @angular/router. ng add @blotch/angular-lynx sets this up for you.

src/app/app.config.ts
import { type ApplicationConfig } from '@angular/core';
import { provideRenderer, provideRouter } from '@blotch/angular-lynx'; 
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRenderer(),
    provideRouter(routes),
  ],
};
src/app/app.routes.ts
import type { Routes } from '@angular/router';
import { Home } from './home/home';
import { Settings } from './settings/settings';

export const routes: Routes = [
  { path: '', pathMatch: 'full', redirectTo: 'home' },
  { path: 'home', component: Home },
  { path: 'settings', component: Settings },
];
  • Give the empty path '' a route. The app always starts at /, and there's no URL bar to start anywhere else. Without an '' route, the first screen is blank.
  • provideRouter() takes the usual router features as extra arguments, such as withComponentInputBinding(), withRouterResources() and withErrorBoundaries().
src/app/app.ts
import { Component } from '@angular/core';
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, RouterOutlet, RouterLink, RouterLinkActive],
  template: `
    <view class="flex flex-row">
      <view class="p-3" routerLink="/home" routerLinkActive="bg-accent">
        <text>Home</text>
      </view>
      <view class="p-3" routerLink="/settings" routerLinkActive="bg-accent">
        <text>Settings</text>
      </view>
    </view>
    <router-outlet />
  `,
})
export class App {}
  • routerLink and routerLinkActive are Angular's own, from @angular/router.
  • A tap on the element navigates. RouterLink listens for click, and AngularLynx hands it the tap, as Lynx for Web does.
  • Put routerLink on any element, usually the <view> around a label.
  • An <a routerLink> works too. It renders as a <text> (see HTML tags).
  • Its inputs work as on the web, such as queryParams, replaceUrl and state. There's no href to show.
  • routerLinkActive adds its classes while the link's route is active. For styling a class can't do, read its state: #link="routerLinkActive", then link.isActive.

While its route is active, LYNX_ELEMENTS adds selected to the element's accessibility-traits. It goes after any traits of the element's own, and comes off again after.

  • iOS announces the element as selected.
  • Android has no selected trait, so there the element keeps its own traits.

See LynxRouterLinkActive for the details.

Tip

For tabs along the bottom of the screen, the Tab Bar component does all of this: npx @blotch/dolan add tab-bar. The Dock is the same as a floating Liquid Glass bar.

src/app/order-row.ts
import { Component, inject } from '@angular/core';
import { Router } from '@angular/router';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-order-row',
  imports: [LYNX_ELEMENTS],
  template: `
    <view (bindtap)="open()">
      <text>Order #1042</text>
    </view>
  `,
})
export class OrderRow {
  readonly #router = inject(Router);

  open(): void {
    this.#router.navigate(['/orders', 1042]);
  }
}
  • Call navigate() or navigateByUrl() straight from a handler, as on the web.
  • Failed navigations don't throw. navigate() resolves to false, for example for a path with no route. Watch Router.events for NavigationError to find out why.

Go back

Use Location.back() from @angular/common:

src/app/details/details.ts
import { Location } from '@angular/common';
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-details',
  imports: [LYNX_ELEMENTS],
  template: ` <view (bindtap)="back()"><text>Back</text></view> `,
})
export class Details {
  readonly #location = inject(Location);

  back(): void {
    this.#location.back(); 
  }
}
  • Location.back() and Location.forward() move through the router's in-memory history.
  • history.back() does nothing on a device, because there's no browser history.
  • For a Back button in a top bar, use the Navigation Bar. It shows its Back button only while there's a screen to go back to, and calls Location.back().

The Android back button

In an app built with ng build --platform android, the Android back button goes back a screen.

  • The router handles it like the browser's back button on the web, so guards such as canDeactivate still run.
  • On the first screen, it leaves the app.
  • A popover or dialog open on top closes first.
  • Your own code can take back with LynxBackButton.

Read route parameters

Turn on withComponentInputBinding() to receive route parameters as inputs:

src/app/app.config.ts
import { type ApplicationConfig } from '@angular/core';
import { withComponentInputBinding } from '@angular/router';
import { provideRenderer, provideRouter } from '@blotch/angular-lynx';
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRenderer(),
    provideRouter(routes, withComponentInputBinding()),
  ],
};
src/app/profile/profile.ts
import { Component, input } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-profile',
  imports: [LYNX_ELEMENTS],
  template: `<text>Profile {{ id() }}</text>`,
})
export class Profile {
  readonly id = input.required<string>(); // from the `profile/:id` route
}

Read parameters reactively, through an input or ActivatedRoute.paramMap, rather than once in ngOnInit.

Angular reuses a component when only the params change, as on the web. /profile/1 and /profile/2 share one component instance, which updates in place.

Lazy-loaded routes

loadComponent works:

src/app/app.routes.ts
import type { Routes } from '@angular/router';

export const routes: Routes = [
  { path: '', pathMatch: 'full', redirectTo: 'home' },
  {
    path: 'home',
    loadComponent: () => import('./home/home').then((m) => m.Home),
  },
];

It doesn't split your code, though. The build keeps every route's code in the bundle, so nothing downloads when the user navigates.

To make the bundle smaller, you can have the build load lazy routes as the app starts: see eagerImports.

Keep a screen alive

Leaving a route destroys its component, as on the web. ngOnDestroy runs, and its state is gone when you come back.

To keepUseUntil
The screens under the top one<lynx-stack-outlet>You go back past them
Each tab, native views and all<lynx-tab-outlet>You leave the outlet
Every route viewLynxRouteReuseStrategyThe app closes

LynxRouteReuseStrategy keeps its views in memory, with their timers and subscriptions running. Their native views are built again each time.

Differences from web Angular

FeatureWeb AngularAngularLynx
URLShown in the address barKept in memory, never shown
Starting URLAny URL the browser opensAlways /
Links<a routerLink>routerLink on any element, <a> too
Active linkaria-current with ariaCurrentWhenActiveThe selected accessibility trait
Going backBrowser back button, history.back()Android back button, Location.back()
TransitionswithViewTransitions()<lynx-stack-outlet>, with swipe back
TabsBuilt again each time you switch to one<lynx-tab-outlet> keeps each one
Lazy routesSeparate files, downloaded on demandPart of the bundle