> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Stack Outlet

The router outlet that keeps a stack of screens and moves between them as native apps do, with a swipe back. `import { LynxStackOutlet, type StackNavigationInfo, LynxStackPage, LynxStackChrome, LynxStackBottomBar } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/app/app.ts"
import { Component } from '@angular/core';
import { LYNX_ELEMENTS, LynxStackOutlet } from '@blotch/angular-lynx';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, LynxStackOutlet],
  template: `<lynx-stack-outlet />`,
})
export class App {}
```

See [Slide screens in and out](/guide/routing/stack.md) for what it does, and which way each navigation moves.

## API

### `LynxStackOutlet`

```typescript
@Component({ selector: 'lynx-stack-outlet', exportAs: 'outlet' })
class LynxStackOutlet extends RouterOutlet {
  readonly animation: InputSignal<StackAnimation | undefined>;
  readonly swipeBack: InputSignalWithTransform<boolean, unknown>;
  readonly pageClass: InputSignal<string>;
  readonly hideBottomBar: InputSignal<StackBottomBarDefault>;
}

type StackAnimation = 'ios' | 'material' | 'none';
type StackBottomBarDefault = 'pushed' | 'never';
```

A `RouterOutlet` that keeps a stack of screens and moves between them as iOS and Android apps do. Use it in place of `<router-outlet>`: it has the same inputs, outputs and API, and the screens under the top one stay alive.

| Input           | Type                    | Default                                    | Description                                                               |
| --------------- | ----------------------- | ------------------------------------------ | ------------------------------------------------------------------------- |
| `animation`     | `StackAnimation`        | `'material'` on Android, `'ios'` elsewhere | How screens move. `'none'` swaps them at once and turns the swipe off.    |
| `swipeBack`     | `boolean`               | `true`                                     | Whether dragging the top screen to the right takes it back.               |
| `pageClass`     | `string`                | `''`                                       | Classes for each screen's frame.                                          |
| `hideBottomBar` | `StackBottomBarDefault` | `'pushed'`                                 | Which screens take the tab bar or dock away when their route doesn't say. |

- **`swipeBack`** takes a drag from the left edge, or from anywhere that doesn't scroll sideways.
- **`pageClass`:** without it, a screen is drawn on `var(--background, #ffffff)`.
- **`hideBottomBar`:** `'pushed'` is every screen pushed over the first, and `'never'` is none.
- **It fills its parent** (`flex: 1`) and clips the screens in it. Each screen sits in a frame of its own, absolutely placed over the others.
- **While Reduce Motion is on,** a push or a pop cross-fades.
- **A swipe goes back through the history,** to the entry before the top screen's, however many it added since. A guard that refuses brings the screen back.
- **A screen pushed over the first takes the bottom bar away,** and says so through [`LynxStackChrome`](#lynxstackchrome). A route's `data: { bottomBar: 'visible' | 'hidden' }` says otherwise for its screen.
- **With `withErrorBoundaries()`,** a screen that throws shows its route's error component in its frame, and `isErrorComponentActive` is `true` while the top screen does, as on `<router-outlet>`. Going back to the screen builds it again. A covered screen that fails gets only `error`: `<router-outlet>` binds the route's params and data to its one active screen, and the router is on the top one, so make the error component's route inputs optional. See [When a screen fails](/guide/routing/stack.md#when-a-screen-fails).

### `StackNavigationInfo`

```typescript
type StackNavigationInfo = {
  readonly stack?: 'push' | 'pop' | 'root';
};
```

What a navigation does to a `LynxStackOutlet`'s stack, when the URL doesn't say it the way you want. Pass it as the navigation's `info`:

- On a `routerLink`: `[info]="{ stack: 'push' }"`
- From code: `router.navigate(commands, { info: { stack: 'root' } })`

| `stack`  | The stack                                                                   |
| -------- | --------------------------------------------------------------------------- |
| `'push'` | Pushes the screen, sliding it in, even at the same depth or already in it.  |
| `'pop'`  | Pops back to the screen. One that isn't in the stack slides in from behind. |
| `'root'` | Starts a new stack with the screen, without a transition.                   |

A [`LynxTabOutlet`](/api/angular-lynx/routing/tab-outlet.md) reads `'root'` too. A navigation to a hidden tab's own URL with `stack: 'root'` goes to that URL, rather than to where the tab was left.

### `LynxStackPage`

```typescript
class LynxStackPage {
  readonly active: Signal<boolean>;
  readonly bottomBarHidden: Signal<boolean>;
}
```

The screen of a `LynxStackOutlet` that a component is on. Any component on it can inject it: `inject(LynxStackPage, { optional: true })`, which is `null` off a stack. It also identifies the screen, for state kept per screen.

| Signal            | What it says                                                                        |
| ----------------- | ----------------------------------------------------------------------------------- |
| `active`          | `true` while the screen is on top. `false` while another covers it or it's leaving. |
| `bottomBarHidden` | `true` when the screen takes the bottom bar away while it's on top.                 |

- **A covered screen's components keep running,** so use `active()` to pause what only matters while it shows.
- **`bottomBarHidden()` doesn't change while the screen is covered.** So a screen can drop the room it keeps at its end for the bar without moving its content under a screen on top. See [`LynxStackChrome`](#lynxstackchrome).

### `LynxStackChrome`

```typescript
@Injectable({ providedIn: 'root' })
class LynxStackChrome {
  readonly bottomBarHidden: Signal<boolean>;
  readonly bottomBarProgress: Signal<number>;
  readonly bottomBarMotion: Signal<StackBarMotion>;
}

type StackBarMotion = {
  readonly animation: 'ios' | 'material' | 'fade' | 'none';
  readonly duration: number;
  readonly easing: string;
  readonly coveredX: number;
};

type StackBottomBar = 'visible' | 'hidden';
```

What the stack that's showing does, for a bar outside it: a tab bar or a dock beside the `<router-outlet>` whose tabs hold `<lynx-stack-outlet>`s.

- **The [Tab Bar](/dolan/tab-bar.md) and the [Dock](/dolan/dock.md) follow it** through [`LynxStackBottomBar`](#lynxstackbottombar), which also has the screen underneath carry the bar on iOS.
- **A bar of your own** can do the same, or read the chrome directly and slide away on its own, as below.

| Signal              | What it says                                                            |
| ------------------- | ----------------------------------------------------------------------- |
| `bottomBarHidden`   | Whether the bar should be away: the screen on top takes it away.        |
| `bottomBarProgress` | How far the bar is away, from `0` (shown) to `1` (gone).                |
| `bottomBarMotion`   | How the bar gets there: the animation, duration, easing and `coveredX`. |

- **`bottomBarHidden`** changes as a push or a pop starts, and when the router goes back after a swipe. It doesn't change while a finger drags. Hide the bar from screen readers and taps while it's `true`.
- **`bottomBarProgress`** follows a finger dragging a screen back, move by move. A push or a pop sets it to where the bar ends up as the screens start to move.
- **`bottomBarMotion.animation`** is the screens' `animation`, or `'fade'` while Reduce Motion cross-fades them.
- **`bottomBarMotion.duration`** (ms) and **`easing`** are the push's or pop's. `duration` is `0` while a finger drags or nothing moves.
- **`bottomBarMotion.coveredX`** is how far the screen under a pushed one moves, as a share of the width (`-0.3` on iOS).

```typescript
@Component({
  selector: 'app-player-bar',
  host: {
    '[style.transform]': 'transform()',
    '[style.transition]': 'transition()',
  },
  template: `…`,
})
export class PlayerBar {
  readonly #chrome = inject(LynxStackChrome);
  protected readonly transform = computed(
    () => `translateY(${this.#chrome.bottomBarProgress() * 100}%)`,
  );
  protected readonly transition = computed(() => {
    const { duration, easing } = this.#chrome.bottomBarMotion();
    return duration > 0 ? `transform ${duration}ms ${easing}` : 'none';
  });
}
```

#### Which screens take the bar away

- **Every screen pushed over a stack's first one,** unless its outlet's `hideBottomBar` is `'never'`.
- **A route says otherwise in its data.** `{ path: 'results', component: Results, data: { bottomBar: 'visible' } }` keeps it. `bottomBar: 'hidden'` takes it away, even from a stack's first screen.
- **Only a stack the app shows counts:** one with a screen the router has active, on screens that are on top of their own stacks. A tab the router has left doesn't hide the bar on another tab, nor does a stack on a covered screen.
- **Stacks inside stacks: the innermost decides.** A screen that doesn't say (a stack's first, or a pushed one under `hideBottomBar="never"`) leaves the bar as the stacks around it have it.
- **On a stack's screen, it follows only the stacks on that screen.** A bar inside a screen moves with the screen, so the stack that moves the screen doesn't move the bar too.

### `LynxStackBottomBar`

```typescript
@Directive({ selector: '[lynxStackBottomBar]', exportAs: 'lynxStackBottomBar' })
class LynxStackBottomBar {
  readonly carried: Signal<boolean>;
  readonly hidden: Signal<boolean>;
  readonly progress: Signal<number>;
  readonly motion: Signal<StackBarMotion>;
}
```

Makes a bottom bar part of the screen that has it while a stack's screens move as iOS's do. UIKit does the same with its tab bar while a navigation controller moves. The [Tab Bar](/dolan/tab-bar.md) and the [Dock](/dolan/dock.md) put it on their hosts.

- **The pushed screen covers the bar** as it covers the screen underneath, with its rounded corner and its shadow.
- **The dark over the screen underneath** dims the bar too.
- **The bar moves with that screen** under a finger.
- **Why not a bar outside the stack:** it would lie over both screens. The best it could do is cut itself off along the pushed screen's edge.

Put it on your bar's host, and move the bar with its signals rather than [`LynxStackChrome`](#lynxstackchrome)'s:

```typescript
@Component({
  selector: 'app-player-bar',
  hostDirectives: [LynxStackBottomBar],
  host: {
    '[style.transform]': 'transform()',
    '[style.transition]': 'transition()',
  },
  template: `…`,
})
export class PlayerBar {
  readonly #bar = inject(LynxStackBottomBar);
  protected readonly transform = computed(
    () => `translateY(${this.#bar.progress() * 100}%)`,
  );
  protected readonly transition = computed(() => {
    const { duration, easing } = this.#bar.motion();
    return duration > 0 ? `transform ${duration}ms ${easing}` : 'none';
  });
}
```

| Signal     | What it says                                                                                                   |
| ---------- | -------------------------------------------------------------------------------------------------------------- |
| `carried`  | Whether a screen carries the bar now: the bar is in that screen, along its bottom, at rest, and moves with it. |
| `hidden`   | The chrome's `bottomBarHidden`. Hide the bar from screen readers and taps while it's `true`.                   |
| `progress` | The chrome's `bottomBarProgress`, or `0` while a screen carries the bar.                                       |
| `motion`   | The chrome's `bottomBarMotion`, with a `duration` of `0` while a screen carries the bar.                       |

While a screen carries the bar, the bar should look as it does at rest.

- **Which screen carries it:** the one that shows the bar, as another screen moves over it or off it. A push carries it in the screen underneath, and a pop or a swipe back carries it back in.
- **How long:** that screen keeps it while it's covered. The bar goes back to its own place once that screen is on top again, or the router leaves the stack (another tab).
- **Where it doesn't carry it:** a screen that's popped, or one a finger drags (which may go), doesn't carry a bar it shows. The bar slides away on its own.
- **Android's motion and the Reduce Motion cross-fade** don't carry it either. `progress` and `motion` are then the chrome's.
- **Where it sits:** absolutely, along the bottom and across the width of the screen carrying it, which fills the stack.
- **So the stack should run to the bottom of the screen,** as it does beside a floating dock, or once a tab bar is out of the layout. (The Tab Bar lies over the stack while it's away or on its way.)
- **Its place:** a comment holds the bar's place in its parent meanwhile, as with CDK's `DomPortal`.

## Related

- [Slide screens in and out](/guide/routing/stack.md): how the stack moves, and the tab bar on pushed screens.
- [Routing](/api/angular-lynx/routing/index.md): `provideRouter()` and the rest of the router API.
- [Tab Outlet](/api/angular-lynx/routing/tab-outlet.md): keeps each tab alive, stacks and all.
- [Location](/api/angular-lynx/routing/location.md): `LynxLocationStrategy.historyIndex`, which the stack's swipe goes back by.
- [Tab Bar](/dolan/tab-bar.md) and [Dock](/dolan/dock.md)
