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

Tab Outlet

The router outlet whose routes are an app's tabs, which it keeps once they've been shown. import { LynxTabOutlet, LynxTabPage } from '@blotch/angular-lynx';

Usage

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

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, LynxTabOutlet],
  template: `<lynx-tab-outlet [prebuild]="['library']" />`,
})
export class App {}

See Keep each tab alive for what it does.

API

LynxTabOutlet

@Component({ selector: 'lynx-tab-outlet', exportAs: 'outlet' })
class LynxTabOutlet extends RouterOutlet {
  readonly keep: InputSignal<readonly string[] | undefined>;
  readonly prebuild: InputSignal<readonly string[] | undefined>;
}

A RouterOutlet whose routes are an app's tabs, which it keeps once they've been shown, as UITabBarController and Material's navigation bar do. Use it in place of <router-outlet> beside a tab bar or a dock: it has the same inputs, outputs and API.

InputTypeDefaultDescription
keepreadonly string[] | undefinedundefinedThe paths of the routes whose tabs are kept while hidden. Without it, every tab is kept.
prebuildreadonly string[] | undefinedundefinedThe paths of the routes whose tabs are built before they're first shown.

For example, [keep]="['home', 'library']" or [prebuild]="['library', 'profile']". A tab built ahead makes the first tap on it as quick as a return.

Which routes are tabs

  • Each route is one tab, whatever its params. /item/1 and /item/2 share the tab of item/:id, as they share its component.
  • A route without a component whose children (children or loadChildren) start with the tab's component on '' is the tab, under its own path. keep, prebuild, and its keepAlive and prebuild data go by it.

Hidden tabs

  • A hidden tab is visibility: hidden and moved out of the outlet, which clips it.
  • Why not display: none: on Lynx, it resizes everything in the tab to 0×0 and loses its scroll positions.
  • A route's data: { keepAlive: false } destroys its tab when it's hidden. keepAlive: true keeps it whatever keep says.
  • A navigation to a hidden tab's own URL goes to the URL the tab was at when it was hidden. A guard the outlet adds to the router's copy of each tab's route does this.
  • These go where they say: Back and Forward, a navigation with a query or a deeper path, and one whose info is { stack: 'root' }.
  • A LynxStackOutlet in a tab keeps its screens while the tab is hidden. When the tab comes back, the stack puts its screens' entries back in the history before the current one, so Back goes through them.
  • With a RouteReuseStrategy that detaches a tab, the outlet hands it over, as <router-outlet> does, and its native views go.
  • With withErrorBoundaries(), a tab that throws shows its route's error component in its frame, and isErrorComponentActive is true while the tab shown does, as on <router-outlet>. A tab showing its error component isn't kept: switching back to it builds it again. A hidden tab that fails gets only error, as the router binds route inputs only for the tab shown, so make the error component's route inputs optional. A tab built ahead that fails in its first check is left out and its error goes to the ErrorHandler: Angular builds no route before the router goes to it, and the boundary's RedirectCommand would navigate away from where you are. See When a tab fails.

Switching tabs

  • The tab left stays on screen until the next one is drawn, then the two swap in a frame.
  • A tab built on its first visit shows once the app's next change detection has drawn its bindings, @if and @for. Until then it held nothing, and the screen would flash white between the two.
  • On iOS, a Core Animation transition that ends while a tab is being built draws the screen partway through. It shows the tab left rather than nothing.

Tabs built ahead

A tab is built ahead when it's in prebuild, or its route has data: { prebuild: true }. The route's data wins over the list either way.

  • When: once the first tab is drawn, one at a time, each between frames. Then it's hidden.
  • What: its component and the screens its URL leads to, with their guards and resolvers run (those of the routes above it too).
  • Its LynxTabPage.active() is false.
  • The router doesn't move: its URL, its history and the tab bar's selection stay put. The router's navigation to the tab shows it as a tab coming back.
  • Which tabs it can build: the routes beside the one shown that have a path without a parameter, and a component or children that start with one on ''.
  • Which it can't: a tab the outlet doesn't keep, or one whose path has a parameter. In development, it warns of a tab it's asked for and can't build.
  • Its elements don't get binduiappear until it's shown.

LynxTabPage

class LynxTabPage {
  readonly active: Signal<boolean>;
}

The tab of a LynxTabOutlet that a component is in. Any component in the tab can inject it, the screens of a stack in the tab included: inject(LynxTabPage, { optional: true }), which is null outside a tab.

  • active() is true while the tab is the one shown.
  • A hidden tab's components keep running, so use active() to pause what only matters while it shows.