SSGOI

Angular

Use the common ssgoi directive above the changing page region and give it an ssgoiFramework that reads Angular Router. The layout boundary directive supplies each page’s boundary.

Setup

import { Component, signal } from "@angular/core";
import { NavigationEnd, Router, RouterOutlet, UrlTree } from "@angular/router";
import { Ssgoi, type SsgoiConfig, type SsgoiFramework } from "@ssgoi/angular";
import { drill } from "@ssgoi/angular/view-transitions";

// Read once by [ssgoi]; the path drops the query string and fragment.
const framework: SsgoiFramework = {
  getRoute: (injector) => {
    const router = injector.get(Router);
    const { root } = router.parseUrl(router.url);
    return { pathname: router.serializeUrl(new UrlTree(root)) };
  },
  onNavigate: (injector, callback) => {
    const subscription = injector.get(Router).events.subscribe((event) => {
      if (event instanceof NavigationEnd) callback();
    });
    return () => subscription.unsubscribe();
  },
};

@Component({
  selector: "app-root",
  standalone: true,
  imports: [RouterOutlet, Ssgoi],
  template: `
    <main
      ssgoi
      [config]="config()"
      [ssgoiFramework]="framework"
      style="position:relative;z-index:0;min-height:100dvh;overflow-x:clip"
    >
      <router-outlet />
    </main>
  `,
})
export class AppComponent {
  protected readonly config = signal<SsgoiConfig>({
    transitions: [
      { on: "/posts/**", except: "/posts", transition: drill() },
    ],
  });
  protected readonly framework = framework;
}

Transition state

A page that scrolls itself on arrival, such as an anchor jump or scrollIntoView, fights the animation. Read the provider's transition state and act once it is idle. The status is idle or transitioning; while transitioning it also carries from, to and direction. It flips as soon as the navigation is paired, one microtask after the DOM changed, and returns to idle when the run releases, the same span the scroll-input lock covers. injectSsgoiTransition returns a readonly signal and stays idle during SSR.

import { Component, effect } from "@angular/core";
import { injectSsgoiTransition } from "@ssgoi/angular";

@Component({ selector: "app-comments", standalone: true, template: "" })
export class CommentsComponent {
  private readonly transition = injectSsgoiTransition();

  constructor() {
    effect(() => {
      if (this.transition().status !== "idle") return;
      document.getElementById("comments")?.scrollIntoView();
    });
  }
}

Angular Router

Experimental API

Bind a framework with getRoute(injector) and onNavigate(injector, callback) to [ssgoiFramework] on the ssgoi element; [ssgoi] reads the route once and shares it with every boundary. The Setup above has the complete object. A structural directive then marks a page’s real DOM root and recreates its embedded view when its route key changes. The application keeps its RouterOutlet.

Connect a routed page

Import the standalone directive from @ssgoi/angular in the routed component. The template must have exactly one DOM root. This also handles parameter changes that reuse the same route component. It throws if the ssgoi element has no ssgoiFramework.

import { Component } from "@angular/core";
import { SsgoiLayoutBoundary } from "@ssgoi/angular";

@Component({
  standalone: true,
  imports: [SsgoiLayoutBoundary],
  template: `
    <article *ssgoiLayoutBoundary="let boundary">
      {{ boundary.id }}
    </article>
  `,
})
export class PageComponent {}

Persistent shells

Declare an outer shell in config.layouts, for example [{ paths: "/shop/**" }], and put *ssgoiLayoutBoundary on both the section layout’s root and its pages’ roots. Depth is automatic; the outer view is kept while navigation stays in the scope, and the inner one is recreated per path. The directive takes no input. Query-only and cancelled navigation preserve the default view. This directive does not coordinate custom RouteReuseStrategy caches, detached outlets, or auxiliary outlet transitions.

Each router connects through the provider's framework prop. Route boundaries explains how to connect another router directly. Transitions and route rules apply across the web frameworks.