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

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

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 for what it does, and which way each navigation moves.

API

LynxStackOutlet

@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.

InputTypeDefaultDescription
animationStackAnimation'material' on Android, 'ios' elsewhereHow screens move. 'none' swaps them at once and turns the swipe off.
swipeBackbooleantrueWhether dragging the top screen to the right takes it back.
pageClassstring''Classes for each screen's frame.
hideBottomBarStackBottomBarDefault'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. 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.

StackNavigationInfo

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' } })
stackThe 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 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

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.

SignalWhat it says
activetrue while the screen is on top. false while another covers it or it's leaving.
bottomBarHiddentrue 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

@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 and the Dock follow it through 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.
SignalWhat it says
bottomBarHiddenWhether the bar should be away: the screen on top takes it away.
bottomBarProgressHow far the bar is away, from 0 (shown) to 1 (gone).
bottomBarMotionHow 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).
@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

@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 and the Dock 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's:

@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';
  });
}
SignalWhat it says
carriedWhether a screen carries the bar now: the bar is in that screen, along its bottom, at rest, and moves with it.
hiddenThe chrome's bottomBarHidden. Hide the bar from screen readers and taps while it's true.
progressThe chrome's bottomBarProgress, or 0 while a screen carries the bar.
motionThe 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.