@real-router/angular 0.23.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -16
- package/dist/fesm2022/real-router-angular-ssr.mjs +228 -311
- package/dist/fesm2022/real-router-angular-ssr.mjs.map +1 -1
- package/dist/fesm2022/real-router-angular.mjs +1712 -2865
- package/dist/fesm2022/real-router-angular.mjs.map +1 -1
- package/dist/package.json +2 -3
- package/dist/types/real-router-angular-ssr.d.ts +55 -45
- package/dist/types/real-router-angular-ssr.d.ts.map +1 -1
- package/dist/types/real-router-angular.d.ts +540 -305
- package/dist/types/real-router-angular.d.ts.map +1 -1
- package/package.json +11 -12
- package/dist/README.md +0 -816
- package/ssr/components/ClientOnly.ts +0 -27
- package/ssr/components/HttpStatusCode.ts +0 -123
- package/ssr/components/ServerOnly.ts +0 -27
- package/ssr/functions/injectDeferred.ts +0 -92
- package/ssr/functions/provideHttpStatusSink.ts +0 -43
- package/ssr/ng-package.json +0 -6
- package/ssr/public_api.ts +0 -35
- package/ssr/utils/createHttpStatusSink.ts +0 -61
package/dist/README.md
DELETED
|
@@ -1,816 +0,0 @@
|
|
|
1
|
-
# @real-router/angular
|
|
2
|
-
|
|
3
|
-
[](../../LICENSE)
|
|
4
|
-
|
|
5
|
-
> Angular 22 integration for [Real-Router](https://github.com/greydragon888/real-router) — inject functions, components, and directives.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @real-router/angular @real-router/core @real-router/browser-plugin
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
**Peer dependencies:** `@angular/core` >= 22.0.0, `@angular/common` >= 22.0.0
|
|
14
|
-
|
|
15
|
-
## Quick Start
|
|
16
|
-
|
|
17
|
-
Bootstrap a standalone Angular application with `provideRealRouter`:
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { bootstrapApplication } from "@angular/platform-browser";
|
|
21
|
-
import { createRouter } from "@real-router/core";
|
|
22
|
-
import { browserPluginFactory } from "@real-router/browser-plugin";
|
|
23
|
-
import { provideRealRouter } from "@real-router/angular";
|
|
24
|
-
import { AppComponent } from "./app.component";
|
|
25
|
-
|
|
26
|
-
const router = createRouter([
|
|
27
|
-
{ name: "home", path: "/" },
|
|
28
|
-
{
|
|
29
|
-
name: "users",
|
|
30
|
-
path: "/users",
|
|
31
|
-
children: [{ name: "profile", path: "/:id" }],
|
|
32
|
-
},
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
router.usePlugin(browserPluginFactory());
|
|
36
|
-
await router.start();
|
|
37
|
-
|
|
38
|
-
bootstrapApplication(AppComponent, {
|
|
39
|
-
providers: [provideRealRouter(router)],
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
> **Lifecycle:** `provideRealRouter(router)` expects a router that has already been started — `await router.start()` MUST run before `bootstrapApplication`. For SSR / SSG, use [`provideRealRouterFactory`](#server-side-rendering) instead — it accepts a non-started `baseRouter` and runs `router.start(url)` itself via `provideAppInitializer`, deriving the URL from Angular's `REQUEST` token.
|
|
44
|
-
|
|
45
|
-
Then use `injectRoute` and `RouteView` in your root component:
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { Component } from "@angular/core";
|
|
49
|
-
import {
|
|
50
|
-
injectRoute,
|
|
51
|
-
RouteView,
|
|
52
|
-
RouteMatch,
|
|
53
|
-
RouteNotFound,
|
|
54
|
-
RealLink,
|
|
55
|
-
} from "@real-router/angular";
|
|
56
|
-
|
|
57
|
-
@Component({
|
|
58
|
-
selector: "app-root",
|
|
59
|
-
imports: [RouteView, RouteMatch, RouteNotFound, RealLink],
|
|
60
|
-
template: `
|
|
61
|
-
<nav>
|
|
62
|
-
<a realLink routeName="home">Home</a>
|
|
63
|
-
<a realLink routeName="users">Users</a>
|
|
64
|
-
</nav>
|
|
65
|
-
|
|
66
|
-
<route-view [routeNode]="''">
|
|
67
|
-
<ng-template routeMatch="home">
|
|
68
|
-
<app-home />
|
|
69
|
-
</ng-template>
|
|
70
|
-
<ng-template routeMatch="users">
|
|
71
|
-
<app-users-layout />
|
|
72
|
-
</ng-template>
|
|
73
|
-
<ng-template routeNotFound>
|
|
74
|
-
<app-not-found />
|
|
75
|
-
</ng-template>
|
|
76
|
-
</route-view>
|
|
77
|
-
`,
|
|
78
|
-
})
|
|
79
|
-
export class AppComponent {
|
|
80
|
-
readonly route = injectRoute();
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
For nested children (e.g., `users.profile`), place another `<route-view>` inside the parent layout and set `routeNode` to the parent's name:
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
@Component({
|
|
88
|
-
selector: "app-users-layout",
|
|
89
|
-
imports: [RouteView, RouteMatch],
|
|
90
|
-
template: `
|
|
91
|
-
<h1>Users</h1>
|
|
92
|
-
<route-view [routeNode]="'users'">
|
|
93
|
-
<ng-template routeMatch="profile">
|
|
94
|
-
<app-user-profile />
|
|
95
|
-
</ng-template>
|
|
96
|
-
</route-view>
|
|
97
|
-
`,
|
|
98
|
-
})
|
|
99
|
-
export class UsersLayoutComponent {}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Functions
|
|
103
|
-
|
|
104
|
-
All inject functions must be called within an injection context (constructor, field initializer, or `runInInjectionContext`). Route state functions return `RouteSignals` — an object with a `routeState` signal and a stable `navigator` reference.
|
|
105
|
-
|
|
106
|
-
| Function | Returns | Reactive? |
|
|
107
|
-
| ------------------------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
108
|
-
| `injectRouter()` | `Router` | Never |
|
|
109
|
-
| `injectNavigator()` | `Navigator` | Never |
|
|
110
|
-
| `injectRoute()` | `RouteSignals` | `routeState` on every navigation |
|
|
111
|
-
| `injectRouteNode(name)` | `RouteSignals` | When the node subtree is entered, left, or changes between descendants (uses `shouldUpdateNode` — sibling-leaf transitions within the same subtree still fire) |
|
|
112
|
-
| `injectRouteUtils()` | `RouteUtils` | Never |
|
|
113
|
-
| `injectRouterTransition()` | `Signal<RouterTransitionSnapshot>` | On transition start/end |
|
|
114
|
-
| `injectIsActiveRoute(name, params?, search?, options?)` | `Signal<boolean>` | On active state change |
|
|
115
|
-
| `injectRouteExit(handler, options?)` | `void` — wraps `subscribeLeave` with abort + same-route guards | Never (handler captured at injection time) |
|
|
116
|
-
| `injectRouteEnter(handler, options?)` | `void` — fires once on nav-driven mount via `effect()` + `transition.from` | Never (handler captured at injection time) |
|
|
117
|
-
|
|
118
|
-
`RouteSignals` shape:
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
interface RouteSignals {
|
|
122
|
-
readonly routeState: Signal<RouteSnapshot>; // { route, previousRoute }
|
|
123
|
-
readonly navigator: Navigator;
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
// injectRouteNode — updates only when "users.*" changes
|
|
129
|
-
@Component({
|
|
130
|
-
selector: "app-users-layout",
|
|
131
|
-
template: `
|
|
132
|
-
@if (route.routeState().route; as r) {
|
|
133
|
-
@switch (r.name) {
|
|
134
|
-
@case ("users") {
|
|
135
|
-
<app-users-list />
|
|
136
|
-
}
|
|
137
|
-
@case ("users.profile") {
|
|
138
|
-
<app-user-profile [id]="r.params['id']" />
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
`,
|
|
143
|
-
})
|
|
144
|
-
export class UsersLayoutComponent {
|
|
145
|
-
readonly route = injectRouteNode("users");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// injectNavigator — stable reference, never reactive
|
|
149
|
-
@Component({
|
|
150
|
-
selector: "app-back-button",
|
|
151
|
-
template: `<button (click)="goHome()">Back</button>`,
|
|
152
|
-
})
|
|
153
|
-
export class BackButtonComponent {
|
|
154
|
-
private readonly navigator = injectNavigator();
|
|
155
|
-
|
|
156
|
-
goHome(): void {
|
|
157
|
-
this.navigator.navigate("home");
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// injectRouterTransition — progress bars, loading states
|
|
162
|
-
@Component({
|
|
163
|
-
selector: "app-progress",
|
|
164
|
-
template: `
|
|
165
|
-
@if (transition().isTransitioning) {
|
|
166
|
-
<div class="progress-bar"></div>
|
|
167
|
-
}
|
|
168
|
-
`,
|
|
169
|
-
})
|
|
170
|
-
export class ProgressComponent {
|
|
171
|
-
readonly transition = injectRouterTransition();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// injectRouteExit — exit animations, draft autosave, AbortSignal-aware cleanup
|
|
175
|
-
@Component({
|
|
176
|
-
selector: "app-fade-out",
|
|
177
|
-
template: `<div #box>...</div>`,
|
|
178
|
-
})
|
|
179
|
-
export class FadeOutComponent {
|
|
180
|
-
private el = viewChild.required<ElementRef<HTMLDivElement>>("box");
|
|
181
|
-
|
|
182
|
-
constructor() {
|
|
183
|
-
injectRouteExit(async ({ signal }) => {
|
|
184
|
-
const el = this.el().nativeElement;
|
|
185
|
-
el.classList.add("fade-out");
|
|
186
|
-
const cleanup = () => el.classList.remove("fade-out");
|
|
187
|
-
signal.addEventListener("abort", cleanup, { once: true });
|
|
188
|
-
el.getBoundingClientRect(); // style flush
|
|
189
|
-
await Promise.allSettled(el.getAnimations().map((a) => a.finished));
|
|
190
|
-
cleanup();
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// injectRouteEnter — page-enter analytics, focus management, entry animations
|
|
196
|
-
@Component({ selector: "app-page-enter", template: "" })
|
|
197
|
-
export class PageEnterAnalyticsComponent {
|
|
198
|
-
constructor() {
|
|
199
|
-
injectRouteEnter(({ route, previousRoute }) => {
|
|
200
|
-
analytics.track("page_enter", {
|
|
201
|
-
route: route.name,
|
|
202
|
-
from: previousRoute.name,
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
> **Angular handler-reactivity:** `inject*` functions run once at construction,
|
|
210
|
-
> so `handler` is captured at injection time. Pass a class method (stable
|
|
211
|
-
> identity) and read signals **inside** the handler body to react to changes.
|
|
212
|
-
> See [CLAUDE.md](./CLAUDE.md) → "injectRouteExit / injectRouteEnter Handler
|
|
213
|
-
> Is Captured At Injection Time".
|
|
214
|
-
|
|
215
|
-
## Components
|
|
216
|
-
|
|
217
|
-
### `<route-view>`
|
|
218
|
-
|
|
219
|
-
Declarative route matching. Renders the first `ng-template[routeMatch]` whose segment matches the active route.
|
|
220
|
-
|
|
221
|
-
```html
|
|
222
|
-
<route-view [routeNode]="''">
|
|
223
|
-
<ng-template routeMatch="users">
|
|
224
|
-
<app-users />
|
|
225
|
-
</ng-template>
|
|
226
|
-
<ng-template routeMatch="settings">
|
|
227
|
-
<app-settings />
|
|
228
|
-
</ng-template>
|
|
229
|
-
<ng-template routeNotFound>
|
|
230
|
-
<app-not-found />
|
|
231
|
-
</ng-template>
|
|
232
|
-
</route-view>
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
The `routeNode` input (aliased from `nodeName`) scopes the view to a subtree. Pass `""` for the root level, or a route name like `"users"` for nested layouts:
|
|
236
|
-
|
|
237
|
-
```html
|
|
238
|
-
<!-- Nested layout: renders when any "users.*" route is active -->
|
|
239
|
-
<route-view [routeNode]="'users'">
|
|
240
|
-
<ng-template routeMatch="profile">
|
|
241
|
-
<app-user-profile />
|
|
242
|
-
</ng-template>
|
|
243
|
-
</route-view>
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
> **Note:** The input is named `routeNode` (not `nodeName`) because `nodeName` is a read-only property on `HTMLElement`. Angular's template binding would fail with the unaliased name.
|
|
247
|
-
|
|
248
|
-
### `<router-error-boundary>`
|
|
249
|
-
|
|
250
|
-
Declarative error handling for navigation errors. Renders its content normally and shows an error template alongside it when a guard rejects or a route is not found.
|
|
251
|
-
|
|
252
|
-
```typescript
|
|
253
|
-
import { RouterErrorBoundary, type ErrorContext } from "@real-router/angular";
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
```html
|
|
257
|
-
<router-error-boundary
|
|
258
|
-
[errorTemplate]="errorTpl"
|
|
259
|
-
(onError)="onNavError($event)"
|
|
260
|
-
>
|
|
261
|
-
<a realLink routeName="protected">Go to Protected</a>
|
|
262
|
-
</router-error-boundary>
|
|
263
|
-
|
|
264
|
-
<ng-template #errorTpl let-error let-reset="resetError">
|
|
265
|
-
<div class="toast">
|
|
266
|
-
{{ error.code }}
|
|
267
|
-
<button (click)="reset()">Dismiss</button>
|
|
268
|
-
</div>
|
|
269
|
-
</ng-template>
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
The template context is typed as `ErrorContext`:
|
|
273
|
-
|
|
274
|
-
```typescript
|
|
275
|
-
interface ErrorContext {
|
|
276
|
-
$implicit: RouterError; // the navigation error
|
|
277
|
-
resetError: () => void; // dismiss the error
|
|
278
|
-
}
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
Auto-resets on the next successful navigation. Works with both `realLink` and imperative `router.navigate()`.
|
|
282
|
-
|
|
283
|
-
### `<navigation-announcer>`
|
|
284
|
-
|
|
285
|
-
WCAG-compliant screen reader announcements for route changes. Add it once near the root of your application:
|
|
286
|
-
|
|
287
|
-
```html
|
|
288
|
-
<navigation-announcer />
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
See the [Accessibility](#accessibility) section for details.
|
|
292
|
-
|
|
293
|
-
### `<client-only>` / `<server-only>` (`@real-router/angular/ssr`)
|
|
294
|
-
|
|
295
|
-
Paired SSR-aware boundaries. `<client-only>` renders the bound `fallback` `TemplateRef` on the server (and on the client first paint, to match SSR HTML), then swaps in the projected children after mount. `<server-only>` is the symmetric inverse.
|
|
296
|
-
|
|
297
|
-
Imported from the `/ssr` subpath (ng-packagr secondary entry-point). The same `/ssr` entry also exposes `injectDeferred()` — see [packages/angular/CLAUDE.md](./CLAUDE.md) — for cross-adapter parity with `@real-router/{react,preact,solid,vue,svelte}/ssr`.
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
import { Component } from "@angular/core";
|
|
301
|
-
import { ClientOnly, ServerOnly } from "@real-router/angular/ssr";
|
|
302
|
-
|
|
303
|
-
@Component({
|
|
304
|
-
selector: "app-home",
|
|
305
|
-
template: `
|
|
306
|
-
<ng-template #loadingTpl>
|
|
307
|
-
<span>Loading…</span>
|
|
308
|
-
</ng-template>
|
|
309
|
-
<client-only [fallback]="loadingTpl">
|
|
310
|
-
<browser-api-widget />
|
|
311
|
-
</client-only>
|
|
312
|
-
|
|
313
|
-
<server-only>
|
|
314
|
-
<seo-meta-strip />
|
|
315
|
-
</server-only>
|
|
316
|
-
`,
|
|
317
|
-
imports: [ClientOnly, ServerOnly],
|
|
318
|
-
})
|
|
319
|
-
export class HomeComponent {}
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
Implementation: `signal(false)` + `afterNextRender(() => mounted.set(true))`. `afterNextRender` is a no-op on the server (Angular runtime guarantees), so SSR naturally lands on the SSR-side branch. End-to-end dogfooding lives in [`examples/web/angular/ssr-examples/ssr/`](../../examples/web/angular/ssr-examples/ssr/) (see `e2e/ssr-boundaries.spec.ts`).
|
|
323
|
-
|
|
324
|
-
### `<http-status-code>` (`@real-router/angular/ssr`)
|
|
325
|
-
|
|
326
|
-
Render-time HTTP status declaration. Writes `code` to the optional `HttpStatusSink` provided via `provideHttpStatusSink`, then renders nothing. Last write wins. No-op when no sink is provided.
|
|
327
|
-
|
|
328
|
-
```typescript
|
|
329
|
-
// not-found.component.ts
|
|
330
|
-
import { Component } from "@angular/core";
|
|
331
|
-
import { HttpStatusCode } from "@real-router/angular/ssr";
|
|
332
|
-
|
|
333
|
-
@Component({
|
|
334
|
-
selector: "app-not-found",
|
|
335
|
-
imports: [HttpStatusCode],
|
|
336
|
-
template: `
|
|
337
|
-
<http-status-code [code]="404" />
|
|
338
|
-
<h1>Page not found</h1>
|
|
339
|
-
`,
|
|
340
|
-
})
|
|
341
|
-
export class NotFoundComponent {}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
// entry-server.ts
|
|
346
|
-
import { bootstrapApplication } from "@angular/platform-browser";
|
|
347
|
-
import {
|
|
348
|
-
createHttpStatusSink,
|
|
349
|
-
provideHttpStatusSink,
|
|
350
|
-
} from "@real-router/angular/ssr";
|
|
351
|
-
|
|
352
|
-
const sink = createHttpStatusSink();
|
|
353
|
-
|
|
354
|
-
await bootstrapApplication(AppRoot, {
|
|
355
|
-
providers: [
|
|
356
|
-
provideRealRouterFactory({ baseRouter }),
|
|
357
|
-
provideHttpStatusSink(sink),
|
|
358
|
-
],
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
response.status(sink.code ?? 200).send(html);
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
`HTTP_STATUS_SINK` is the underlying `InjectionToken` — inject it directly with `{ optional: true }` if you need to read the sink in your own components. `createHttpStatusSink()` constructs a fresh `{ code: number | undefined }` per request — read `sink.code` after the SSR render pass to set the response status. Loader-driven errors (`LoaderNotFound` → 404, `LoaderRedirect` → 30x) keep working as before; `<http-status-code>` covers render-time decisions only.
|
|
365
|
-
|
|
366
|
-
### `injectDeferred()` (`@real-router/angular/ssr`)
|
|
367
|
-
|
|
368
|
-
Reads `state.context.ssrDataDeferred[key]` (populated by `defer()` in `@real-router/ssr-data-plugin`). Returns `Signal<T | undefined>` — `undefined` before the promise settles, the resolved value once it does. Compose with `@if` or the `async` pipe for pending UI:
|
|
369
|
-
|
|
370
|
-
```typescript
|
|
371
|
-
import { Component } from "@angular/core";
|
|
372
|
-
import { injectDeferred } from "@real-router/angular/ssr";
|
|
373
|
-
|
|
374
|
-
@Component({
|
|
375
|
-
template: `
|
|
376
|
-
@if (reviews(); as r) {
|
|
377
|
-
@for (review of r; track review.id) {
|
|
378
|
-
<li>{{ review.author }}</li>
|
|
379
|
-
}
|
|
380
|
-
} @else {
|
|
381
|
-
<p>Loading reviews…</p>
|
|
382
|
-
}
|
|
383
|
-
`,
|
|
384
|
-
})
|
|
385
|
-
export class ReviewsComponent {
|
|
386
|
-
readonly reviews = injectDeferred<Review[]>("reviews");
|
|
387
|
-
}
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
**Full `/ssr` surface** (8 exports): `ClientOnly`, `ServerOnly`, `HttpStatusCode`, `injectDeferred`, `provideHttpStatusSink`, `HTTP_STATUS_SINK`, `createHttpStatusSink`, plus the `HttpStatusSink` type. See [`packages/angular/CLAUDE.md`](./CLAUDE.md#ssr-feature-surface--real-routerangularssr) for the implementation notes.
|
|
391
|
-
|
|
392
|
-
## Directives
|
|
393
|
-
|
|
394
|
-
### `realLink`
|
|
395
|
-
|
|
396
|
-
Navigation directive for `<a>` elements. Handles click events, sets `href`, and applies an active CSS class automatically.
|
|
397
|
-
|
|
398
|
-
```html
|
|
399
|
-
<a realLink routeName="users.profile" [routeParams]="{ id: '123' }">
|
|
400
|
-
View Profile
|
|
401
|
-
</a>
|
|
402
|
-
|
|
403
|
-
<a
|
|
404
|
-
realLink
|
|
405
|
-
routeName="users.profile"
|
|
406
|
-
[routeParams]="{ id: '123' }"
|
|
407
|
-
[routeSearch]="{ tab: 'posts' }"
|
|
408
|
-
activeClassName="is-active"
|
|
409
|
-
[activeStrict]="false"
|
|
410
|
-
[ignoreQueryParams]="true"
|
|
411
|
-
[routeOptions]="{ replace: true }"
|
|
412
|
-
>
|
|
413
|
-
View Profile
|
|
414
|
-
</a>
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
| Input | Type | Default | Description |
|
|
418
|
-
| ------------------- | ------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
419
|
-
| `routeName` | `string` | `""` | Target route name |
|
|
420
|
-
| `routeParams` | `Params` | `undefined` | Route (path) parameters (omitted → `undefined`, shares one active-route source with `injectIsActiveRoute(name)`, #776) |
|
|
421
|
-
| `routeSearch` | `SearchParams` | `undefined` | Query (search) params for the link's target (RFC-4 M2, #1548) — parallel to `routeParams`, the path/query split's view-layer channel |
|
|
422
|
-
| `routeOptions` | `NavigationOptions` | `{}` | Navigation options (replace, etc.) |
|
|
423
|
-
| `activeClassName` | `string` | `"active"` | CSS class applied when route is active |
|
|
424
|
-
| `activeStrict` | `boolean` | `false` | Exact match only (no ancestor match) |
|
|
425
|
-
| `ignoreQueryParams` | `boolean` | `true` | Query params don't affect active state |
|
|
426
|
-
| `hash` | `string` | `undefined` | URL fragment (decoded). Tri-state: undefined preserves, `""` clears, value sets. (#532) |
|
|
427
|
-
|
|
428
|
-
#### `hash` input — URL fragment / tab-style UIs
|
|
429
|
-
|
|
430
|
-
```html
|
|
431
|
-
<a realLink [routeName]="'settings'" [hash]="'profile'">Profile</a>
|
|
432
|
-
<a realLink [routeName]="'settings'" [hash]="'account'">Account</a>
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
Active class is hash-aware — only the matching tab lights up. Live demo: [`examples/web/react/hash-examples/link-hash/`](../../examples/web/react/hash-examples/link-hash/) — behavior is identical across adapters, only template syntax differs. See the [Hash Fragment Support](https://github.com/greydragon888/real-router/wiki/Hash) wiki page for the full surface.
|
|
436
|
-
|
|
437
|
-
#### Object `routeParams` — content-stabilized
|
|
438
|
-
|
|
439
|
-
`RealLink` and `RealLinkActive` stabilize `routeParams` by **content** (`shallowEqual` — `Object.is` per key, key-order-insensitive), so an inline `[routeParams]="{ id: '123' }"` literal that Angular re-allocates on every change detection does **not** re-create the active-route source or re-run `buildHref` until the param content actually changes (#988). Binding a stable reference (a component field or signal) was already churn-free; this closes the gap for inline literals.
|
|
440
|
-
|
|
441
|
-
Caveat: nested object/array param **values** are compared by reference, not deep — stabilize them with a `signal`/`computed` if it matters:
|
|
442
|
-
|
|
443
|
-
```ts
|
|
444
|
-
// flat params — stable across change detection, recompute only on real change
|
|
445
|
-
@Component({ template: `<a realLink routeName="items.item" [routeParams]="{ id }" />` })
|
|
446
|
-
// nested value — fresh ref each CD → href/active recompute every CD; stabilize:
|
|
447
|
-
readonly params = computed(() => ({ filters: [1, 2] }));
|
|
448
|
-
// <a realLink routeName="search" [routeParams]="params()" />
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
`routeSearch` is **not** content-stabilized the same way (#1548) — an inline `[routeSearch]="{ tab: 'x' }"` literal re-creates the active-route source and re-runs `buildHref` on every change detection, even when the query content is unchanged. Bind a stable reference (a component field or signal) if churn matters for your use case.
|
|
452
|
-
|
|
453
|
-
### `[realLinkActive]`
|
|
454
|
-
|
|
455
|
-
Applies an active CSS class to any element when a route is active. Use this when you need active state on a non-`<a>` element, or when the clickable element and the styled element are different.
|
|
456
|
-
|
|
457
|
-
```html
|
|
458
|
-
<li [realLinkActive]="'active'" routeName="users">
|
|
459
|
-
<a realLink routeName="users">Users</a>
|
|
460
|
-
</li>
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
| Input | Type | Default | Description |
|
|
464
|
-
| ------------------- | --------- | ----------- | ---------------------------------------------- |
|
|
465
|
-
| `realLinkActive` | `string` | `""` | CSS class to apply when active |
|
|
466
|
-
| `routeName` | `string` | `""` | Route to watch |
|
|
467
|
-
| `routeParams` | `Params` | `undefined` | Route parameters (omitted → `undefined`, #776) |
|
|
468
|
-
| `activeStrict` | `boolean` | `false` | Exact match only |
|
|
469
|
-
| `ignoreQueryParams` | `boolean` | `true` | Query params don't affect active state |
|
|
470
|
-
|
|
471
|
-
### `routeMatch`
|
|
472
|
-
|
|
473
|
-
Structural directive used inside `<route-view>`. Marks an `ng-template` as the content to render when a route segment matches.
|
|
474
|
-
|
|
475
|
-
```html
|
|
476
|
-
<ng-template routeMatch="home">
|
|
477
|
-
<app-home />
|
|
478
|
-
</ng-template>
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
### `routeSelf`
|
|
482
|
-
|
|
483
|
-
Structural directive used inside `<route-view>`. Marks an `ng-template` as the exact-match slot for the parent `<route-view>`'s `routeNode` — it renders only when `state.name === routeNode()`. Useful for nodes that have both an "index" view and child routes:
|
|
484
|
-
|
|
485
|
-
```html
|
|
486
|
-
<route-view [routeNode]="'users'">
|
|
487
|
-
<ng-template routeSelf>
|
|
488
|
-
<!-- shown when route is exactly "users" -->
|
|
489
|
-
<app-users-list />
|
|
490
|
-
</ng-template>
|
|
491
|
-
<ng-template routeMatch="profile">
|
|
492
|
-
<!-- shown when route is "users.profile" -->
|
|
493
|
-
<app-user-profile />
|
|
494
|
-
</ng-template>
|
|
495
|
-
</route-view>
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
**Template priority** inside `<route-view>`: `routeMatch` (segment prefix) → `routeSelf` (exact-match for `routeNode`) → `routeNotFound` (`UNKNOWN_ROUTE` only). First-wins for all three — `routeMatch`, `routeSelf`, and `routeNotFound` (#1439): the first matching template in declaration order wins, later duplicates are ignored.
|
|
499
|
-
|
|
500
|
-
### `routeNotFound`
|
|
501
|
-
|
|
502
|
-
Structural directive used inside `<route-view>`. Marks an `ng-template` as the fallback when no segment matches and the route is `UNKNOWN_ROUTE`.
|
|
503
|
-
|
|
504
|
-
```html
|
|
505
|
-
<ng-template routeNotFound>
|
|
506
|
-
<app-not-found />
|
|
507
|
-
</ng-template>
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
## Accessibility
|
|
511
|
-
|
|
512
|
-
Add `<navigation-announcer>` once near the root of your application to enable WCAG-compliant screen reader announcements on every route change:
|
|
513
|
-
|
|
514
|
-
```typescript
|
|
515
|
-
import { NavigationAnnouncer } from "@real-router/angular";
|
|
516
|
-
|
|
517
|
-
@Component({
|
|
518
|
-
selector: "app-root",
|
|
519
|
-
imports: [NavigationAnnouncer],
|
|
520
|
-
template: `
|
|
521
|
-
<navigation-announcer />
|
|
522
|
-
<!-- rest of your app -->
|
|
523
|
-
`,
|
|
524
|
-
})
|
|
525
|
-
export class AppComponent {}
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
The announcer creates a visually hidden `aria-live` region and announces each navigation to screen readers. See the [Accessibility guide](https://github.com/greydragon888/real-router/wiki/Accessibility) for details.
|
|
529
|
-
|
|
530
|
-
`<navigation-announcer>` accepts optional `[prefix]` and `[getAnnouncementText]` signal inputs to customize the announced text:
|
|
531
|
-
|
|
532
|
-
| Input | Type | Description |
|
|
533
|
-
| ----------------------- | -------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
534
|
-
| `[prefix]` | `string` | Prefix prepended to the resolved text (default `"Navigated to "`) |
|
|
535
|
-
| `[getAnnouncementText]` | `(route: State) => string` | Full custom text; overrides the default `h1 → title → route-name` chain (falls back on empty/throw) |
|
|
536
|
-
|
|
537
|
-
```typescript
|
|
538
|
-
@Component({
|
|
539
|
-
imports: [NavigationAnnouncer],
|
|
540
|
-
template: `<navigation-announcer [getAnnouncementText]="announce" />`,
|
|
541
|
-
})
|
|
542
|
-
export class AppComponent {
|
|
543
|
-
announce = (route: State): string => `Now on ${route.name}`;
|
|
544
|
-
}
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
## Scroll Restoration
|
|
548
|
-
|
|
549
|
-
Opt-in via the `provideRealRouter` options bag:
|
|
550
|
-
|
|
551
|
-
```typescript
|
|
552
|
-
import { provideRealRouter } from "@real-router/angular";
|
|
553
|
-
|
|
554
|
-
bootstrapApplication(AppComponent, {
|
|
555
|
-
providers: [
|
|
556
|
-
provideRealRouter(router, {
|
|
557
|
-
scrollRestoration: { mode: "restore" },
|
|
558
|
-
}),
|
|
559
|
-
],
|
|
560
|
-
});
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
`RealRouterOptions` shape:
|
|
564
|
-
|
|
565
|
-
```typescript
|
|
566
|
-
interface RealRouterOptions {
|
|
567
|
-
scrollRestoration?: ScrollRestorationOptions; // { mode?, anchorScrolling?, scrollContainer? }
|
|
568
|
-
scrollSpy?: ScrollSpyOptions; // { selector, rootMargin?, scrollContainer? } — #575
|
|
569
|
-
viewTransitions?: boolean;
|
|
570
|
-
}
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
Restores scroll on back/forward, scrolls to top (or `#hash`) on push. Three modes: `"restore"` (default), `"top"`, `"native"`. Custom containers via `scrollContainer: () => HTMLElement | null`. The utility is created by `provideEnvironmentInitializer` and torn down via `inject(DestroyRef)`. Options are a snapshot at bootstrap — not reactive to runtime changes. Under `@real-router/browser-plugin`, replace transitions now preserve scroll position and programmatic reloads restore from `sessionStorage` (portable via `state.transition.replace` / `state.transition.reload`). See [Scroll Restoration guide](https://github.com/greydragon888/real-router/wiki/Scroll-Restoration) for the full behaviour matrix.
|
|
574
|
-
|
|
575
|
-
## Scroll Spy
|
|
576
|
-
|
|
577
|
-
Opt into router-coordinated `IntersectionObserver`-driven URL hash spy via the same options bag:
|
|
578
|
-
|
|
579
|
-
```typescript
|
|
580
|
-
bootstrapApplication(AppComponent, {
|
|
581
|
-
providers: [
|
|
582
|
-
provideRealRouter(router, {
|
|
583
|
-
scrollSpy: { selector: "[id]:is(h2,h3)" },
|
|
584
|
-
}),
|
|
585
|
-
],
|
|
586
|
-
});
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
The URL hash tracks the topmost visible anchor as the user scrolls, syncing `state.context.url.hash` so sibling `<a realLink [hash]>` highlights stay current. Emits a forced same-route transition with `{ hash, replace: true, force: true, hashChange: true }` — same write API as `<a realLink [hash]>` (#532), `replace: true` so spy doesn't pollute history. Anti-flicker gates: `isTransitioning` (skip emits during transitions), `coolingDown` (skip emits during smooth `scrollIntoView` after a hash click; cleared on `scrollend` or 500 ms timeout), `selfEmitting` (spy doesn't rate-limit itself). Hardcoded internals: rAF + 150 ms trailing debounce, MutationObserver re-observe debounced 250 ms.
|
|
590
|
-
|
|
591
|
-
Options: `{ selector: string, rootMargin?: string, scrollContainer?: () => HTMLElement | null }`. Default `rootMargin`: `"-20% 0px -60% 0px"`. Empty `selector` / `undefined` = off. SSR / browsers without `IntersectionObserver` = NOOP. Requires `browser-plugin` or `navigation-plugin` (hash-plugin / memory-plugin → warn-once + NOOP). The utility is installed via `provideEnvironmentInitializer` (`installScrollSpy`) and torn down on `DestroyRef`; options are a snapshot at bootstrap, not reactive.
|
|
592
|
-
|
|
593
|
-
Available on both `provideRealRouter(router, { scrollSpy })` (SPA) and `provideRealRouterFactory({ baseRouter, scrollSpy })` (SSR). On the SSR path the utility is correctly NOOP'd on the server pass (`document` is undefined). Behaviour is identical to the React adapter — see the [React Scroll Spy demo](../../examples/web/react/hash-examples/scroll-spy/) (12 sections, TOC sidebar, 10 e2e scenarios) and the [Scroll Spy guide](https://github.com/greydragon888/real-router/wiki/Scroll-Spy).
|
|
594
|
-
|
|
595
|
-
## Server-Side Rendering
|
|
596
|
-
|
|
597
|
-
For Angular SSR (`@angular/ssr` with `outputMode: "server"`) and SSG build-time render via `renderApplication`, use `provideRealRouterFactory` instead of `provideRealRouter`. The factory creates a per-request router clone via Angular's `REQUEST: InjectionToken<Request | null>`, runs `router.start(url)` through `provideAppInitializer`, and disposes the router on `DestroyRef`:
|
|
598
|
-
|
|
599
|
-
```typescript
|
|
600
|
-
import { provideRealRouterFactory } from "@real-router/angular";
|
|
601
|
-
import { browserPluginFactory } from "@real-router/browser-plugin";
|
|
602
|
-
import { ssrDataPluginFactory } from "@real-router/ssr-data-plugin";
|
|
603
|
-
|
|
604
|
-
const baseRouter = createRouter(routes);
|
|
605
|
-
|
|
606
|
-
export const appConfig: ApplicationConfig = {
|
|
607
|
-
providers: [
|
|
608
|
-
provideRealRouterFactory({
|
|
609
|
-
baseRouter,
|
|
610
|
-
plugins: (request) =>
|
|
611
|
-
request
|
|
612
|
-
? [ssrDataPluginFactory(loaders)]
|
|
613
|
-
: [browserPluginFactory(), ssrDataPluginFactory(loaders)],
|
|
614
|
-
deps: (request) => ({
|
|
615
|
-
currentUser: request
|
|
616
|
-
? parseCookies(request.headers.get("cookie"))
|
|
617
|
-
: parseCookies(document.cookie),
|
|
618
|
-
}),
|
|
619
|
-
}),
|
|
620
|
-
],
|
|
621
|
-
};
|
|
622
|
-
```
|
|
623
|
-
|
|
624
|
-
Existing `provideRealRouter(router)` is unchanged — keep using it for SPA / post-hydrate scenarios. Both APIs ship in parallel; pick one for the whole application.
|
|
625
|
-
|
|
626
|
-
### Working examples
|
|
627
|
-
|
|
628
|
-
**SPA examples** — `provideRealRouter(router)` after `await router.start()`:
|
|
629
|
-
|
|
630
|
-
| Example | Demonstrates |
|
|
631
|
-
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
632
|
-
| [`examples/web/angular/basic/`](../../examples/web/angular/basic) | Minimal setup with `RouteView` + `RealLink` + `injectRoute` |
|
|
633
|
-
| [`examples/web/angular/combined/`](../../examples/web/angular/combined) | All features combined: nested routes, dynamic params, lazy loading, persistent params |
|
|
634
|
-
| [`examples/web/angular/dynamic-routes/`](../../examples/web/angular/dynamic-routes) | `:id` params, programmatic navigation |
|
|
635
|
-
| [`examples/web/angular/hash-routing/`](../../examples/web/angular/hash-routing) | `hash-plugin` with `<a realLink hash="…">` tab-style UIs (#532) |
|
|
636
|
-
| [`examples/web/angular/lazy-loading/`](../../examples/web/angular/lazy-loading) | Route-level code-splitting via `import()` |
|
|
637
|
-
| [`examples/web/angular/nested-routes/`](../../examples/web/angular/nested-routes) | Multi-level `<route-view>` composition |
|
|
638
|
-
| [`examples/web/angular/persistent-params/`](../../examples/web/angular/persistent-params) | `persistent-params-plugin` integration |
|
|
639
|
-
| [`examples/web/angular/animation-examples/`](../../examples/web/angular/animation-examples) | View Transitions API + scroll restoration + direction-tracker patterns |
|
|
640
|
-
|
|
641
|
-
**SSR / SSG examples** — `provideRealRouterFactory({ baseRouter, plugins, deps })`:
|
|
642
|
-
|
|
643
|
-
| Example | Demonstrates |
|
|
644
|
-
| ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
645
|
-
| [`examples/web/angular/ssr-examples/ssr/`](../../examples/web/angular/ssr-examples/ssr) | Classical SSR with cookie-based DI, auth guards, nested loaders |
|
|
646
|
-
| [`examples/web/angular/ssr-examples/ssr-mixed/`](../../examples/web/angular/ssr-examples/ssr-mixed) | Mixed SSR/CSR routes — some routes server-rendered, others CSR-only |
|
|
647
|
-
| [`examples/web/angular/ssr-examples/ssr-streaming/`](../../examples/web/angular/ssr-examples/ssr-streaming) | Streaming SSR with `@defer (on viewport)` + `@defer (on hover)` + incremental hydration |
|
|
648
|
-
| [`examples/web/angular/ssr-examples/ssg/`](../../examples/web/angular/ssr-examples/ssg) | Static site generation via in-process AngularNodeAppEngine + `getStaticPaths()` |
|
|
649
|
-
|
|
650
|
-
**Post-hydration loader skip (#599)** — `provideRealRouterFactory` automatically bridges Angular's `TransferState` to the cross-adapter hydration scratchpad. On the server pass, the resolved router state is written to `TransferState`; on the client, the bootstrap consumes the seed via `hydrateRouter(...)` and `ssr-data-plugin` reuses the server-resolved `state.context.data` without re-invoking the loader on first paint. Requires `provideServerRendering()` (server) + `provideClientHydration()` (client) — both standard for Angular SSR apps. Verified end-to-end in `ssr/` and `ssr-streaming/` examples via `window.__LOADER_CALLS__` counter assertion.
|
|
651
|
-
|
|
652
|
-
See [CLAUDE.md → SSR Support](./CLAUDE.md#ssr-support) for the full decision matrix, lifecycle diagram, plugin separation guidance, decision matrix, and known constraints.
|
|
653
|
-
|
|
654
|
-
## View Transitions
|
|
655
|
-
|
|
656
|
-
Opt-in animated route transitions via the browser's [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API):
|
|
657
|
-
|
|
658
|
-
```typescript
|
|
659
|
-
import { provideRealRouter } from "@real-router/angular";
|
|
660
|
-
|
|
661
|
-
bootstrapApplication(AppComponent, {
|
|
662
|
-
providers: [provideRealRouter(router, { viewTransitions: true })],
|
|
663
|
-
});
|
|
664
|
-
```
|
|
665
|
-
|
|
666
|
-
No-op on unsupported browsers (Firefox as of 2026-04, SSR). Utility is created by `provideEnvironmentInitializer` at bootstrap and torn down via `inject(DestroyRef)`. Option is a snapshot at bootstrap — not reactive to runtime changes. Customization is pure CSS via `::view-transition-*` pseudo-elements and `view-transition-name` for hero morphs. See [View Transitions guide](https://github.com/greydragon888/real-router/wiki/View-Transitions) for patterns.
|
|
667
|
-
|
|
668
|
-
## Navigation Direction
|
|
669
|
-
|
|
670
|
-
`createDirectionTracker(router)` writes `data-nav-direction="forward" | "back"` on `<html>` on every leave, so exit and entry animations can key off the direction. Install it **before** `router.usePlugin(browserPluginFactory())`: both listen to `popstate`, and the tracker has to see the event first.
|
|
671
|
-
|
|
672
|
-
```typescript
|
|
673
|
-
import { browserPluginFactory } from "@real-router/browser-plugin";
|
|
674
|
-
import { createRouter } from "@real-router/core";
|
|
675
|
-
import {
|
|
676
|
-
createDirectionTracker,
|
|
677
|
-
provideRealRouter,
|
|
678
|
-
} from "@real-router/angular";
|
|
679
|
-
|
|
680
|
-
const router = createRouter(routes);
|
|
681
|
-
|
|
682
|
-
createDirectionTracker(router); // before usePlugin
|
|
683
|
-
router.usePlugin(browserPluginFactory());
|
|
684
|
-
|
|
685
|
-
bootstrapApplication(AppComponent, {
|
|
686
|
-
providers: [provideRealRouter(router)],
|
|
687
|
-
});
|
|
688
|
-
```
|
|
689
|
-
|
|
690
|
-
```css
|
|
691
|
-
html[data-nav-direction="back"] .page {
|
|
692
|
-
animation-name: slide-in-from-left;
|
|
693
|
-
}
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
`destroy()` removes the listener and the attribute. Without a `document` (SSR) it returns a no-op instance. The argument must be a live `Router`: the tracker follows its transitions through `getPluginApi`. The API is unstable — it may change in a minor release. Live demo: [`examples/web/angular/animation-examples/route-animations/`](../../examples/web/angular/animation-examples/route-animations/). Recipes: [Routing Animations guide](https://github.com/greydragon888/real-router/wiki/Routing-Animations).
|
|
697
|
-
|
|
698
|
-
## Angular-Specific Patterns
|
|
699
|
-
|
|
700
|
-
### Signals, Not Observables
|
|
701
|
-
|
|
702
|
-
`injectRoute()` and `injectRouteNode()` return Angular signals, not RxJS observables. Read them in templates directly or call them in computed/effect:
|
|
703
|
-
|
|
704
|
-
```typescript
|
|
705
|
-
@Component({
|
|
706
|
-
template: `
|
|
707
|
-
@if (route.routeState().route; as r) {
|
|
708
|
-
<h1>{{ r.name }}</h1>
|
|
709
|
-
}
|
|
710
|
-
`,
|
|
711
|
-
})
|
|
712
|
-
export class PageComponent {
|
|
713
|
-
readonly route = injectRoute();
|
|
714
|
-
}
|
|
715
|
-
```
|
|
716
|
-
|
|
717
|
-
To react to changes in class code, use `effect`:
|
|
718
|
-
|
|
719
|
-
```typescript
|
|
720
|
-
import { effect } from "@angular/core";
|
|
721
|
-
|
|
722
|
-
export class PageComponent {
|
|
723
|
-
readonly route = injectRouteNode("users");
|
|
724
|
-
|
|
725
|
-
constructor() {
|
|
726
|
-
effect(() => {
|
|
727
|
-
const r = this.route.routeState().route;
|
|
728
|
-
if (r) {
|
|
729
|
-
document.title = `Users — ${r.params["id"] ?? "list"}`;
|
|
730
|
-
}
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
```
|
|
735
|
-
|
|
736
|
-
### Injection Context
|
|
737
|
-
|
|
738
|
-
All `inject*` functions must be called within an injection context. The constructor and field initializers are both valid:
|
|
739
|
-
|
|
740
|
-
```typescript
|
|
741
|
-
// Field initializer — preferred
|
|
742
|
-
export class MyComponent {
|
|
743
|
-
readonly route = injectRoute(); // valid
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
// Constructor — also valid
|
|
747
|
-
export class MyComponent {
|
|
748
|
-
readonly route: RouteSignals;
|
|
749
|
-
|
|
750
|
-
constructor() {
|
|
751
|
-
this.route = injectRoute(); // valid
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// Outside injection context — throws
|
|
756
|
-
export class MyComponent {
|
|
757
|
-
ngOnInit() {
|
|
758
|
-
const route = injectRoute(); // ERROR: not in injection context
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
```
|
|
762
|
-
|
|
763
|
-
`sourceToSignal` follows the same rule — it calls `inject(DestroyRef)` internally.
|
|
764
|
-
|
|
765
|
-
### DestroyRef for Cleanup
|
|
766
|
-
|
|
767
|
-
Subscriptions created by `sourceToSignal` and the directives clean up automatically via `DestroyRef.onDestroy`. No manual unsubscribe needed.
|
|
768
|
-
|
|
769
|
-
### Zoneless Compatibility
|
|
770
|
-
|
|
771
|
-
The adapter is signal-first and does not depend on Zone.js. It works with `provideExperimentalZonelessChangeDetection()` out of the box.
|
|
772
|
-
|
|
773
|
-
### Reactive Source Setup via `effect()` (#630)
|
|
774
|
-
|
|
775
|
-
`RealLink`, `RealLinkActive`, and `RouteView` create their subscription sources inside `effect(...)` blocks scheduled from the **constructor** (not `ngOnInit`). Reading signal inputs inside `effect()` makes the source-creation REACTIVE — when `[realLink]`, `[routeParams]`, `[routeSearch]`, `[hash]`, `[realLinkActive]`, or `[routeNode]` change in AOT, the effect tears down the previous source via `onCleanup` and creates a new one with the current input values. The legacy `ngOnInit` setup captured inputs once at mount and produced a real AOT bug (#630). Effect cleanup is bound automatically to the host directive's injection-context `DestroyRef`.
|
|
776
|
-
|
|
777
|
-
In `RealLink` / `RealLinkActive`, `[routeParams]` is routed through `shallowEqual` content-stabilization before the effect reads it, so an inline-literal binding re-allocated on every change detection only re-creates the source on real content change (see [Object `routeParams`](#object-routeparams--content-stabilized), #988).
|
|
778
|
-
|
|
779
|
-
## Signal Bridge
|
|
780
|
-
|
|
781
|
-
### `sourceToSignal(source)`
|
|
782
|
-
|
|
783
|
-
Bridges any `RouterSource<T>` (from `@real-router/sources`) into an Angular `Signal<T>`. Cleanup wires through `inject(DestroyRef)` — must be called in an injection context. Used internally by `RouterErrorBoundary`; exposed for custom composables that need to bridge router sources into reactive signals.
|
|
784
|
-
|
|
785
|
-
```typescript
|
|
786
|
-
import { sourceToSignal } from "@real-router/angular";
|
|
787
|
-
import { createTransitionSource } from "@real-router/sources";
|
|
788
|
-
|
|
789
|
-
const transitionSignal = sourceToSignal(createTransitionSource(router));
|
|
790
|
-
```
|
|
791
|
-
|
|
792
|
-
## Documentation
|
|
793
|
-
|
|
794
|
-
Full documentation: [Wiki](https://github.com/greydragon888/real-router/wiki) — start with the [Angular Integration guide](https://github.com/greydragon888/real-router/wiki/Angular-Integration) for Angular-specific examples and gotchas.
|
|
795
|
-
|
|
796
|
-
The shared (cross-framework) wiki pages use the `use*` naming convention — they cover every adapter (React, Preact, Solid, Vue, Svelte, Angular) and each page has an explicit Angular section showing the `inject*` form:
|
|
797
|
-
|
|
798
|
-
- [RouterProvider](https://github.com/greydragon888/real-router/wiki/RouterProvider) · [RouteView](https://github.com/greydragon888/real-router/wiki/RouteView) · [RouterErrorBoundary](https://github.com/greydragon888/real-router/wiki/RouterErrorBoundary) · [Scroll Restoration](https://github.com/greydragon888/real-router/wiki/Scroll-Restoration) · [Scroll Spy](https://github.com/greydragon888/real-router/wiki/Scroll-Spy)
|
|
799
|
-
- [useRouter → `injectRouter`](https://github.com/greydragon888/real-router/wiki/useRouter) · [useRoute → `injectRoute`](https://github.com/greydragon888/real-router/wiki/useRoute) · [useRouteNode → `injectRouteNode`](https://github.com/greydragon888/real-router/wiki/useRouteNode) · [useNavigator → `injectNavigator`](https://github.com/greydragon888/real-router/wiki/useNavigator) · [useRouteUtils → `injectRouteUtils`](https://github.com/greydragon888/real-router/wiki/useRouteUtils) · [useRouterTransition → `injectRouterTransition`](https://github.com/greydragon888/real-router/wiki/useRouterTransition) · [useRouteExit → `injectRouteExit`](https://github.com/greydragon888/real-router/wiki/useRouteExit) · [useRouteEnter → `injectRouteEnter`](https://github.com/greydragon888/real-router/wiki/useRouteEnter)
|
|
800
|
-
|
|
801
|
-
## Related Packages
|
|
802
|
-
|
|
803
|
-
| Package | Description |
|
|
804
|
-
| ---------------------------------------------------------------------------------------- | --------------------------------------- |
|
|
805
|
-
| [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required dependency) |
|
|
806
|
-
| [@real-router/browser-plugin](https://www.npmjs.com/package/@real-router/browser-plugin) | Browser History API integration |
|
|
807
|
-
| [@real-router/sources](https://www.npmjs.com/package/@real-router/sources) | Subscription layer (used internally) |
|
|
808
|
-
| [@real-router/route-utils](https://www.npmjs.com/package/@real-router/route-utils) | Route tree queries (`injectRouteUtils`) |
|
|
809
|
-
|
|
810
|
-
## Contributing
|
|
811
|
-
|
|
812
|
-
See [contributing guidelines](../../CONTRIBUTING.md) for development setup and PR process.
|
|
813
|
-
|
|
814
|
-
## License
|
|
815
|
-
|
|
816
|
-
[MIT](../../LICENSE) © [Oleg Ivanov](https://github.com/greydragon888)
|