Reactive route data with Signals
Status and setup
withRouterResources() and route resources are developer preview APIs. They are opt-in; the generated starter keeps stable resolvers. FastAng remains zoneless. This example adds no FastAng resource wrapper.
@sinclair/typebox@^0.34.41 in your starter. Copy the complete files below, then run npm run build and open /resources/Ada after starting the server. For pnpm use pnpm add @sinclair/typebox@^0.34.41 and pnpm run build.
app.config.ts. In an existing app merge the providers and choose your own navigation-error policy. The example replaces the greeting endpoint with its contract-based equivalent; keep the existing resolver and page.
Application configuration
import { inject, type ApplicationConfig } from '@angular/core';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { provideClientHydration } from '@angular/platform-browser';
import {
provideRouter, withComponentInputBinding, withRouterResources,
withNavigationErrorHandler, RedirectCommand, Router,
} from '@angular/router';
import { createRoutes } from './fastang.routes';
export function createAppConfig(): ApplicationConfig {
return {
providers: [
provideRouter(
createRoutes(),
withComponentInputBinding(),
withRouterResources(),
// Demo policy: show a dedicated page if a blocking resource fails.
withNavigationErrorHandler(() =>
new RedirectCommand(inject(Router).parseUrl('/resource-error')),
),
),
provideHttpClient(withFetch()),
provideClientHydration(),
],
};
}Shared contract and endpoint
import { Type } from '@sinclair/typebox';
import { defineApiContract } from '@fastang/core/contracts';
export const greetingContract = defineApiContract({
method: 'GET', path: '/api/greet/:name',
schema: {
params: Type.Object({ name: Type.String({ minLength: 1, maxLength: 80 }) }),
response: { 200: Type.Object({ message: Type.String() }, { additionalProperties: false }) },
},
});import { defineContractRoute } from '@fastang/core/contract-route';
import { greetingContract } from '../../../shared/greeting';
export default defineContractRoute(greetingContract, {
handler: async request => ({ message: `Hello, ${request.params.name}!` }),
});Reactive route metadata
import { httpResource } from '@angular/common/http';
import { computed, inject } from '@angular/core';
import { Router, type Route } from '@angular/router';
import { apiUrl, type ApiSuccess } from '@fastang/core/contracts';
import { greetingContract } from '../../../shared/greeting';
export default {
title: 'Reactive greeting · FastAng',
canActivate: [route => route.queryParamMap.get('preview') === 'blocked'
? inject(Router).createUrlTree(['/about'])
: true],
runGuardsAndResolvers: 'paramsOrQueryParamsChange',
resources: ({ params }) => {
// Keep unrelated query navigation from rebuilding the HTTP request.
const name = computed(() => params()['name']);
return {
greeting: httpResource<ApiSuccess<typeof greetingContract>>(() =>
apiUrl(greetingContract, { params: { name: name() } }),
),
};
},
} satisfies Pick<Route, 'title' | 'canActivate' | 'runGuardsAndResolvers' | 'resources'>;Signal Inputs and error page
import { Component, computed, inject, input } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import type { ApiSuccess } from '@fastang/core/contracts';
import type { greetingContract } from '../../../shared/greeting';
@Component({
imports: [RouterLink],
template: `
<p class="eyebrow">ROUTER RESOURCES / DEVELOPER PREVIEW</p>
<h1>{{ greeting().message }}</h1>
<p>Route parameter: <strong>{{ name() }}</strong></p>
@if (mode() === 'details') {
<p data-testid="resource-details">
A typed contract builds the URL. Angular loads the resource before activation.
</p>
}
<nav aria-label="Reactive greetings">
<a routerLink="/resources/Ada">Ada</a>
<a routerLink="/resources/Grace">Grace</a>
<a [routerLink]="['/resources', name()]" [queryParams]="{ mode: 'details' }">Details</a>
<a [routerLink]="['/resources', invalidName]">API failure</a>
<a [routerLink]="['/resources', name()]" [queryParams]="{ preview: 'blocked' }">Redirect</a>
</nav>
@if (navigating()) { <p role="status">Loading page…</p> }
`,
})
export default class ResourceGreetingPage {
readonly name = input.required<string>();
readonly greeting = input.required<ApiSuccess<typeof greetingContract>>();
readonly mode = input('summary', {
transform: (value: string | undefined) => value === 'details' ? 'details' : 'summary',
});
private readonly router = inject(Router);
readonly navigating = computed(() => this.router.currentNavigation() !== null);
readonly invalidName = 'a'.repeat(81);
}import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
@Component({
imports: [RouterLink],
template: `
<h1>Greeting unavailable.</h1>
<p>The navigation failed. Try a valid name or return to your application.</p>
<a routerLink="/resources/Ada">Try again</a>
`,
})
export default class ResourceErrorPage {}Behavior to verify
Load /resources/Ada: SSR includesHello, Ada!; the blocking resource value
greeting input before the component activates.
Navigate to Grace: namechanges and the resource loads the new API URL.Choose Details: modechanges without reloading the greeting. Onlynameis a
mode means summary.
Choose API failure: validation rejects the oversized name. The navigation error
/resource-error; Try again recovers with a valid name.
Choose Redirect: the guard sends navigation to /aboutbefore loading the resource.
mode transform normalizes its query input; the API validates the name through the contract. apiUrl infers URL inputs, and ApiSuccess supplies the response type; neither validates the response in the browser.
computed isolates the name from replacement parameter objects during query navigation. runGuardsAndResolvers also reruns the guard when query values change.
SSR and compatibility boundaries
httpResource uses HttpClient, including the local SSR dispatch and native HTTP transfer cache. Eligible public responses are reused during hydration. Requests carrying Cookie or Authorization are excluded and may fetch again in the browser. No shared HTML cache is introduced. Resource instances must be created inside the route factory; never export a resource instance as module-level shared state.
httpResource route resources. It does not claim blanket compatibility for nonBlocking, arbitrary resource loaders or direct fetch, which may bypass the HTTP bridge. Keep the stable resolver approach when you do not want preview APIs.