@mmstack/router-core 20.4.1 → 21.0.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 CHANGED
@@ -1,322 +1,322 @@
1
- # @mmstack/router-core
2
-
3
- Core utilities and Signal-based primitives for enhancing development with `@angular/router`. This library provides helpers for common routing tasks, reactive integration with router state, and intelligent module preloading.
4
-
5
- Part of the `@mmstack` ecosystem, designed to complement [@mmstack/primitives](https://www.npmjs.com/package/@mmstack/primitives).
6
-
7
- [![npm version](https://badge.fury.io/js/%40mmstack%2Frouter-core.svg)](https://badge.fury.io/js/%40mmstack%2Frouter-core)
8
-
9
- ## Installation
10
-
11
- ```bash
12
- npm install @mmstack/router-core
13
- ```
14
-
15
- ## Signal Utilities
16
-
17
- This library includes helpers to interact with router state reactively using Angular Signals.
18
-
19
- ---
20
-
21
- ### queryParam
22
-
23
- Creates a WritableSignal that synchronizes with a specific URL query parameter, enabling two-way binding between the signal's state and the URL.
24
-
25
- - Reading the signal returns the parameter's current value (string) or null if absent.
26
- - Setting the signal to a string updates the URL parameter.
27
- - Setting the signal to null removes the parameter from the URL.
28
- - Reacts to external navigation changes affecting the parameter.
29
- - Supports static or dynamic (function/signal) keys.
30
-
31
- ```typescript
32
- @Component({
33
- selector: 'app-search-page',
34
- standalone: true,
35
- imports: [FormsModule],
36
- template: `
37
- <label>
38
- Search:
39
- <input [(ngModel)]="searchTerm" placeholder="Enter search term..." />
40
- </label>
41
- <button (click)="searchTerm.set(null)" [disabled]="!searchTerm()">Clear</button>
42
- <p>Current search: {{ searchTerm() ?? 'None' }}</p>
43
- `,
44
- })
45
- export class SearchPageComponent {
46
- // Two-way bind the 'q' query parameter (?q=...)
47
- protected readonly searchTerm = queryParam('q');
48
-
49
- constructor() {
50
- effect(() => {
51
- const currentTerm = this.searchTerm();
52
- console.log('Search term changed:', currentTerm);
53
- // Trigger API call, update results, etc. based on currentTerm
54
- });
55
- }
56
- }
57
- ```
58
-
59
- ### url
60
-
61
- Creates a read-only Signal that tracks the current router URL string.
62
-
63
- - Updates after each successful navigation.
64
- - Reflects the URL after any redirects (urlAfterRedirects).
65
- - Initializes with the router's current URL synchronously.
66
-
67
- ```typescript
68
- import { Component, effect } from '@angular/core';
69
- import { url } from '@mmstack/router-core';
70
-
71
- @Component({
72
- selector: 'app-header',
73
- standalone: true,
74
- template: `<nav>Current Path: {{ currentUrl() }}</nav>`,
75
- })
76
- export class HeaderComponent {
77
- protected readonly currentUrl = url();
78
- }
79
- ```
80
-
81
- ## Preloading Utilities
82
-
83
- ---
84
-
85
- Enhance your application's performance by preloading Angular modules. This library provides a flexible directive and a smart preloading strategy to load modules just before they are needed.
86
-
87
- ### PreloadStrategy
88
-
89
- This is a custom Angular PreloadingStrategy that works in tandem with the mmstack `Link` (via an internal `PreloadService`) to intelligently preload lazy-loaded modules.
90
-
91
- **Features**:
92
-
93
- - Listens for preload requests triggered by the `Link` directive.
94
- - Uses advanced path matching to identify the correct route to preload, even with route parameters and matrix parameters.
95
- - Avoids preloading if the connection is slow (e.g., '2g' effective type) or if the user has data-saving enabled in their browser.
96
- - Respects a `data: { preload: false }` flag in route configurations to explicitly disable preloading for specific routes.
97
- - Prevents redundant preloading attempts for the same route path.
98
-
99
- To enable this preloading strategy, you need to provide it in your application's main routing configuration.
100
-
101
- ```typescript
102
- import { PreloadStrategy } from '@mmstack/router-core';
103
- import { ApplicationConfig } from '@angular/core';
104
- import { provideRouter, withPreloading } from '@angular/router';
105
- import { routes } from './app.routes';
106
-
107
- export const appConfig: ApplicationConfig = {
108
- providers: [
109
- //...other providers
110
- provideRouter(routes, withPreloading(PreloadStrategy)),
111
- ],
112
- };
113
- ```
114
-
115
- ### Link (mmLink)
116
-
117
- The `Link` directive (used with the `mmLink` attribute) is an enhancement for Angular's standard `RouterLink` directive. It adds the capability to preload the JavaScript modules associated with the linked route, based on user interaction or visibility. Other than the added `preloadOn` input & `preloading` output it directly proxies `RouterLink`.
118
-
119
- - `preloadOn`: `input<'hover' | 'visible' | null>()` [default: 'hover'] specifies when to preload, `null` disables preloading
120
- - `preloading` - `output<void>()` fires when route is registered for preloading (before load)
121
-
122
- To use it simply replace any exiting routerLinks that you would like to enable preloading on with the mmLink, you can keep all existing inputs the same. And add the mmstack `PreloadStrategy` in your configuration
123
-
124
- ```typescript
125
- import { Link } from '@mmstack/router-core';
126
- import { RouterLink } from '@angular/router';
127
-
128
- @Component({
129
- selector: 'app-navigation',
130
- standalone: true,
131
- imports: [Link, RouterLink],
132
- template: `
133
- <nav>
134
- <!-- preload on hover -->
135
- <a [mmLink]="['/features']" preloadOn="hover">Features</a>
136
- <!-- preload on visible -->
137
- <a [mmLink]="['/pricing']" preloadOn="visible">Pricing</a>
138
- <!-- no preload -->
139
- <a [mmLink]="['/contact']" [preloadOn]="null">Contact</a>
140
- <!-- preload on hover -->
141
- <a [mmLink]="['/about']">About</a>
142
- <!-- no preload, or just use [preloadOn]="null" -->
143
- <a [routerLink]="['/terms']">Terms & Conditions</a>
144
- </nav>
145
- `,
146
- })
147
- export class NavigationComponent {}
148
- ```
149
-
150
- ## Headless breadcrumb utilities
151
-
152
- This library includes a signal-based, headless toolkit for generating and managing breadcrumbs in your Angular application. It provides the logic to derive breadcrumb data from your routes, allowing you to easily build a completely custom breadcrumb UI component & let the library worry about active routes :)
153
-
154
- ### Consuming breadcrumbs
155
-
156
- The primary way to access the breadcrumb data is via the `injectBreadcrumbs` function. It returns a `Signal<Breadcrumb[]>` that updates automatically as navigation changes. Each `Breadcrumb` object in the array contains reactive signals for its `label`, `link`, `ariaLabel`, and a static id for iteration purposes.
157
-
158
- ```typescript
159
- import { Component } from '@angular/core';
160
- import { injectBreadcrumbs } from '@mmstack/router-core'; // Adjust path if needed
161
-
162
- @Component({
163
- selector: 'app-breadcrumbs',
164
- standalone: true,
165
- template: `
166
- <nav aria-label="breadcrumb">
167
- <ol>
168
- @for (crumb of breadcrumbs(); track crumb.id) {
169
- <li>
170
- <a [href]="crumb.link()" [attr.aria-label]="crumb.ariaLabel()">{{ crumb.label() }}</a>
171
- </li>
172
- }
173
- </ol>
174
- </nav>
175
- `,
176
- })
177
- export class CustomBreadcrumbsComponent {
178
- protected readonly breadcrumbs = injectBreadcrumbs();
179
- }
180
- ```
181
-
182
- ### Registering custom breadcrumbs
183
-
184
- For routes where automatic breadcrumb generation isn't sufficient or when you need more control, you can manually define breadcrumbs using the `createBreadcrumb` route resolver.
185
-
186
- This function allows you to specify the label (static or dynamic via a function) and other properties for a breadcrumb associated with a particular route.
187
- You can use injection in the factory function, as you would with any resolver, making translations or subscribing to dynamic data a breaze! :)
188
-
189
- ```typescript
190
- import { Routes } from '@angular/router';
191
- import { createBreadcrumb } from '@mmstack/router-core';
192
- import { HomeComponent } from './home.component';
193
- import { UserProfileComponent } from './user-profile.component';
194
- import { UserStore } from './user.store';
195
- import { inject } from '@angular/core';
196
- import { AdminComponent } from './admin.component';
197
-
198
- export const appRoutes: Routes = [
199
- {
200
- path: 'home',
201
- component: HomeComponent,
202
- resolve: {
203
- // Simple static breadcrumb
204
- breadcrumb: createBreadcrumb(() => ({
205
- label: 'Home',
206
- })),
207
- },
208
- },
209
- {
210
- path: 'admin',
211
- component: AdminComponent,
212
- data: {
213
- skipBreadcrumb: true, // opt out of auto-generation for this specific route
214
- },
215
- },
216
- {
217
- path: 'users/:userId',
218
- component: UserProfileComponent,
219
- resolve: {
220
- breadcrumb: createBreadcrumb(() => {
221
- const userStore = inject(UserStore);
222
- return {
223
- label: () => `Profile: ${userStore.currentUser().name}` ?? 'Loading...',
224
- ariaLabel: () => `View profile for ${userStore.currentUser().name ?? 'user'}`,
225
- };
226
- }),
227
- },
228
- },
229
- ];
230
- ```
231
-
232
- ### Configuration [optional]
233
-
234
- The breadcrumb system can be configured globally using `provideBreadcrumbConfig`. This allows you to, for example, set the system to 'manual' mode (disabling all automatic generation) or provide a custom function for generating breadcrumb labels.
235
-
236
- ```typescript
237
- import { provideRouter } from '@angular/router';
238
- import { provideBreadcrumbConfig, BreadcrumbConfig, ResolvedLeafRoute } from '@mmstack/router-core'; // Adjust path
239
- import { appRoutes } from './app.routes';
240
- import { ApplicationConfig } from '@angular/core';
241
-
242
- // Example: Custom label generation strategy
243
- const customLabelStrategy = () => {
244
- // you can inject root injectable services/stores here.
245
- return (leaf: ResolvedLeafRoute): string => {
246
- return leaf.route.data?.['navTitle'] || leaf.route.title || 'Default Title';
247
- };
248
- };
249
- export const appConfig: ApplicationConfig = {
250
- providers: [
251
- // ...rest
252
- provideBreadcrumbConfig({
253
- // generation: 'manual' // When set to 'manual' the system only uses explicitly defined breadcrumbs
254
- generation: customLabelStrategy, // Or provide a custom generation function
255
- }),
256
- ],
257
- };
258
- ```
259
-
260
- ## Title utilities
261
-
262
- This library provides a helper function, `createTitle`, to set the document title dynamically from within your route configuration. It integrates seamlessly with Angular's built-in `title` property on routes, allowing for both static and signal-based reactive titles.
263
-
264
- By default, the system will use a title defined on a route's `data` or `title` property. createTitle enhances this by allowing titles to be derived from reactive state.
265
-
266
- ### Using `createTitle`
267
-
268
- The `createTitle` function is a route resolver that returns a title string. You use it directly in the `title` property of a route definition. It can accept a function that returns a static string or a function that returns a dynamic string (which will be converted to a `signal`).
269
-
270
- ```typescript
271
- import { Routes } from '@angular/router';
272
- import { createTitle } from '@mmstack/router-core';
273
- import { inject } from '@angular/core';
274
- import { ProductStore } from './product.store';
275
-
276
- export const appRoutes: Routes = [
277
- {
278
- path: 'about',
279
- // Example 1: Static title
280
- resolve: {
281
- title: createTitle(() => 'About Us'), // static
282
- },
283
- loadComponent: () => import('./about.component').then((m) => m.AboutComponent),
284
- },
285
- {
286
- path: 'products/:id',
287
- // Example 2: Dynamic, signal-based title from a store
288
- resolve: {
289
- title: createTitle(() => {
290
- const productStore = inject(ProductStore);
291
- // The inner function creates a computed signal under the hood
292
- return () => `Product: ${productStore.product().name ?? 'Loading...'}`;
293
- }),
294
- },
295
- loadComponent: () => import('./product-detail.component').then((m) => m.ProductComponent),
296
- },
297
- ];
298
- ```
299
-
300
- ### Configuration [optional]
301
-
302
- You can provide a global configuration to prepend or append text to all titles using provideTitleConfig.
303
-
304
- ```typescript
305
- import { provideRouter } from '@angular/router';
306
- import { provideTitleConfig } from '@mmstack/router-core';
307
- import { appRoutes } from './app.routes';
308
- import { ApplicationConfig } from '@angular/core';
309
-
310
- export const appConfig: ApplicationConfig = {
311
- providers: [
312
- provideRouter(appRoutes),
313
- provideTitleConfig({
314
- // Prefix can be a static string...
315
- // prefix: 'My Awesome App | '
316
-
317
- // ...or a function for more control over the format
318
- prefix: (title) => (title ? `${title} - MyApp` : 'MyApp'),
319
- }),
320
- ],
321
- };
322
- ```
1
+ # @mmstack/router-core
2
+
3
+ Core utilities and Signal-based primitives for enhancing development with `@angular/router`. This library provides helpers for common routing tasks, reactive integration with router state, and intelligent module preloading.
4
+
5
+ Part of the `@mmstack` ecosystem, designed to complement [@mmstack/primitives](https://www.npmjs.com/package/@mmstack/primitives).
6
+
7
+ [![npm version](https://badge.fury.io/js/%40mmstack%2Frouter-core.svg)](https://badge.fury.io/js/%40mmstack%2Frouter-core)
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @mmstack/router-core
13
+ ```
14
+
15
+ ## Signal Utilities
16
+
17
+ This library includes helpers to interact with router state reactively using Angular Signals.
18
+
19
+ ---
20
+
21
+ ### queryParam
22
+
23
+ Creates a WritableSignal that synchronizes with a specific URL query parameter, enabling two-way binding between the signal's state and the URL.
24
+
25
+ - Reading the signal returns the parameter's current value (string) or null if absent.
26
+ - Setting the signal to a string updates the URL parameter.
27
+ - Setting the signal to null removes the parameter from the URL.
28
+ - Reacts to external navigation changes affecting the parameter.
29
+ - Supports static or dynamic (function/signal) keys.
30
+
31
+ ```typescript
32
+ @Component({
33
+ selector: 'app-search-page',
34
+ standalone: true,
35
+ imports: [FormsModule],
36
+ template: `
37
+ <label>
38
+ Search:
39
+ <input [(ngModel)]="searchTerm" placeholder="Enter search term..." />
40
+ </label>
41
+ <button (click)="searchTerm.set(null)" [disabled]="!searchTerm()">Clear</button>
42
+ <p>Current search: {{ searchTerm() ?? 'None' }}</p>
43
+ `,
44
+ })
45
+ export class SearchPageComponent {
46
+ // Two-way bind the 'q' query parameter (?q=...)
47
+ protected readonly searchTerm = queryParam('q');
48
+
49
+ constructor() {
50
+ effect(() => {
51
+ const currentTerm = this.searchTerm();
52
+ console.log('Search term changed:', currentTerm);
53
+ // Trigger API call, update results, etc. based on currentTerm
54
+ });
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### url
60
+
61
+ Creates a read-only Signal that tracks the current router URL string.
62
+
63
+ - Updates after each successful navigation.
64
+ - Reflects the URL after any redirects (urlAfterRedirects).
65
+ - Initializes with the router's current URL synchronously.
66
+
67
+ ```typescript
68
+ import { Component, effect } from '@angular/core';
69
+ import { url } from '@mmstack/router-core';
70
+
71
+ @Component({
72
+ selector: 'app-header',
73
+ standalone: true,
74
+ template: `<nav>Current Path: {{ currentUrl() }}</nav>`,
75
+ })
76
+ export class HeaderComponent {
77
+ protected readonly currentUrl = url();
78
+ }
79
+ ```
80
+
81
+ ## Preloading Utilities
82
+
83
+ ---
84
+
85
+ Enhance your application's performance by preloading Angular modules. This library provides a flexible directive and a smart preloading strategy to load modules just before they are needed.
86
+
87
+ ### PreloadStrategy
88
+
89
+ This is a custom Angular PreloadingStrategy that works in tandem with the mmstack `Link` (via an internal `PreloadService`) to intelligently preload lazy-loaded modules.
90
+
91
+ **Features**:
92
+
93
+ - Listens for preload requests triggered by the `Link` directive.
94
+ - Uses advanced path matching to identify the correct route to preload, even with route parameters and matrix parameters.
95
+ - Avoids preloading if the connection is slow (e.g., '2g' effective type) or if the user has data-saving enabled in their browser.
96
+ - Respects a `data: { preload: false }` flag in route configurations to explicitly disable preloading for specific routes.
97
+ - Prevents redundant preloading attempts for the same route path.
98
+
99
+ To enable this preloading strategy, you need to provide it in your application's main routing configuration.
100
+
101
+ ```typescript
102
+ import { PreloadStrategy } from '@mmstack/router-core';
103
+ import { ApplicationConfig } from '@angular/core';
104
+ import { provideRouter, withPreloading } from '@angular/router';
105
+ import { routes } from './app.routes';
106
+
107
+ export const appConfig: ApplicationConfig = {
108
+ providers: [
109
+ //...other providers
110
+ provideRouter(routes, withPreloading(PreloadStrategy)),
111
+ ],
112
+ };
113
+ ```
114
+
115
+ ### Link (mmLink)
116
+
117
+ The `Link` directive (used with the `mmLink` attribute) is an enhancement for Angular's standard `RouterLink` directive. It adds the capability to preload the JavaScript modules associated with the linked route, based on user interaction or visibility. Other than the added `preloadOn` input & `preloading` output it directly proxies `RouterLink`.
118
+
119
+ - `preloadOn`: `input<'hover' | 'visible' | null>()` [default: 'hover'] specifies when to preload, `null` disables preloading
120
+ - `preloading` - `output<void>()` fires when route is registered for preloading (before load)
121
+
122
+ To use it simply replace any exiting routerLinks that you would like to enable preloading on with the mmLink, you can keep all existing inputs the same. And add the mmstack `PreloadStrategy` in your configuration
123
+
124
+ ```typescript
125
+ import { Link } from '@mmstack/router-core';
126
+ import { RouterLink } from '@angular/router';
127
+
128
+ @Component({
129
+ selector: 'app-navigation',
130
+ standalone: true,
131
+ imports: [Link, RouterLink],
132
+ template: `
133
+ <nav>
134
+ <!-- preload on hover -->
135
+ <a [mmLink]="['/features']" preloadOn="hover">Features</a>
136
+ <!-- preload on visible -->
137
+ <a [mmLink]="['/pricing']" preloadOn="visible">Pricing</a>
138
+ <!-- no preload -->
139
+ <a [mmLink]="['/contact']" [preloadOn]="null">Contact</a>
140
+ <!-- preload on hover -->
141
+ <a [mmLink]="['/about']">About</a>
142
+ <!-- no preload, or just use [preloadOn]="null" -->
143
+ <a [routerLink]="['/terms']">Terms & Conditions</a>
144
+ </nav>
145
+ `,
146
+ })
147
+ export class NavigationComponent {}
148
+ ```
149
+
150
+ ## Headless breadcrumb utilities
151
+
152
+ This library includes a signal-based, headless toolkit for generating and managing breadcrumbs in your Angular application. It provides the logic to derive breadcrumb data from your routes, allowing you to easily build a completely custom breadcrumb UI component & let the library worry about active routes :)
153
+
154
+ ### Consuming breadcrumbs
155
+
156
+ The primary way to access the breadcrumb data is via the `injectBreadcrumbs` function. It returns a `Signal<Breadcrumb[]>` that updates automatically as navigation changes. Each `Breadcrumb` object in the array contains reactive signals for its `label`, `link`, `ariaLabel`, and a static id for iteration purposes.
157
+
158
+ ```typescript
159
+ import { Component } from '@angular/core';
160
+ import { injectBreadcrumbs } from '@mmstack/router-core'; // Adjust path if needed
161
+
162
+ @Component({
163
+ selector: 'app-breadcrumbs',
164
+ standalone: true,
165
+ template: `
166
+ <nav aria-label="breadcrumb">
167
+ <ol>
168
+ @for (crumb of breadcrumbs(); track crumb.id) {
169
+ <li>
170
+ <a [href]="crumb.link()" [attr.aria-label]="crumb.ariaLabel()">{{ crumb.label() }}</a>
171
+ </li>
172
+ }
173
+ </ol>
174
+ </nav>
175
+ `,
176
+ })
177
+ export class CustomBreadcrumbsComponent {
178
+ protected readonly breadcrumbs = injectBreadcrumbs();
179
+ }
180
+ ```
181
+
182
+ ### Registering custom breadcrumbs
183
+
184
+ For routes where automatic breadcrumb generation isn't sufficient or when you need more control, you can manually define breadcrumbs using the `createBreadcrumb` route resolver.
185
+
186
+ This function allows you to specify the label (static or dynamic via a function) and other properties for a breadcrumb associated with a particular route.
187
+ You can use injection in the factory function, as you would with any resolver, making translations or subscribing to dynamic data a breaze! :)
188
+
189
+ ```typescript
190
+ import { Routes } from '@angular/router';
191
+ import { createBreadcrumb } from '@mmstack/router-core';
192
+ import { HomeComponent } from './home.component';
193
+ import { UserProfileComponent } from './user-profile.component';
194
+ import { UserStore } from './user.store';
195
+ import { inject } from '@angular/core';
196
+ import { AdminComponent } from './admin.component';
197
+
198
+ export const appRoutes: Routes = [
199
+ {
200
+ path: 'home',
201
+ component: HomeComponent,
202
+ resolve: {
203
+ // Simple static breadcrumb
204
+ breadcrumb: createBreadcrumb(() => ({
205
+ label: 'Home',
206
+ })),
207
+ },
208
+ },
209
+ {
210
+ path: 'admin',
211
+ component: AdminComponent,
212
+ data: {
213
+ skipBreadcrumb: true, // opt out of auto-generation for this specific route
214
+ },
215
+ },
216
+ {
217
+ path: 'users/:userId',
218
+ component: UserProfileComponent,
219
+ resolve: {
220
+ breadcrumb: createBreadcrumb(() => {
221
+ const userStore = inject(UserStore);
222
+ return {
223
+ label: () => `Profile: ${userStore.currentUser().name}` ?? 'Loading...',
224
+ ariaLabel: () => `View profile for ${userStore.currentUser().name ?? 'user'}`,
225
+ };
226
+ }),
227
+ },
228
+ },
229
+ ];
230
+ ```
231
+
232
+ ### Configuration [optional]
233
+
234
+ The breadcrumb system can be configured globally using `provideBreadcrumbConfig`. This allows you to, for example, set the system to 'manual' mode (disabling all automatic generation) or provide a custom function for generating breadcrumb labels.
235
+
236
+ ```typescript
237
+ import { provideRouter } from '@angular/router';
238
+ import { provideBreadcrumbConfig, BreadcrumbConfig, ResolvedLeafRoute } from '@mmstack/router-core'; // Adjust path
239
+ import { appRoutes } from './app.routes';
240
+ import { ApplicationConfig } from '@angular/core';
241
+
242
+ // Example: Custom label generation strategy
243
+ const customLabelStrategy = () => {
244
+ // you can inject root injectable services/stores here.
245
+ return (leaf: ResolvedLeafRoute): string => {
246
+ return leaf.route.data?.['navTitle'] || leaf.route.title || 'Default Title';
247
+ };
248
+ };
249
+ export const appConfig: ApplicationConfig = {
250
+ providers: [
251
+ // ...rest
252
+ provideBreadcrumbConfig({
253
+ // generation: 'manual' // When set to 'manual' the system only uses explicitly defined breadcrumbs
254
+ generation: customLabelStrategy, // Or provide a custom generation function
255
+ }),
256
+ ],
257
+ };
258
+ ```
259
+
260
+ ## Title utilities
261
+
262
+ This library provides a helper function, `createTitle`, to set the document title dynamically from within your route configuration. It integrates seamlessly with Angular's built-in `title` property on routes, allowing for both static and signal-based reactive titles.
263
+
264
+ By default, the system will use a title defined on a route's `data` or `title` property. createTitle enhances this by allowing titles to be derived from reactive state.
265
+
266
+ ### Using `createTitle`
267
+
268
+ The `createTitle` function is a route resolver that returns a title string. You use it directly in the `title` property of a route definition. It can accept a function that returns a static string or a function that returns a dynamic string (which will be converted to a `signal`).
269
+
270
+ ```typescript
271
+ import { Routes } from '@angular/router';
272
+ import { createTitle } from '@mmstack/router-core';
273
+ import { inject } from '@angular/core';
274
+ import { ProductStore } from './product.store';
275
+
276
+ export const appRoutes: Routes = [
277
+ {
278
+ path: 'about',
279
+ // Example 1: Static title
280
+ resolve: {
281
+ title: createTitle(() => 'About Us'), // static
282
+ },
283
+ loadComponent: () => import('./about.component').then((m) => m.AboutComponent),
284
+ },
285
+ {
286
+ path: 'products/:id',
287
+ // Example 2: Dynamic, signal-based title from a store
288
+ resolve: {
289
+ title: createTitle(() => {
290
+ const productStore = inject(ProductStore);
291
+ // The inner function creates a computed signal under the hood
292
+ return () => `Product: ${productStore.product().name ?? 'Loading...'}`;
293
+ }),
294
+ },
295
+ loadComponent: () => import('./product-detail.component').then((m) => m.ProductComponent),
296
+ },
297
+ ];
298
+ ```
299
+
300
+ ### Configuration [optional]
301
+
302
+ You can provide a global configuration to prepend or append text to all titles using provideTitleConfig.
303
+
304
+ ```typescript
305
+ import { provideRouter } from '@angular/router';
306
+ import { provideTitleConfig } from '@mmstack/router-core';
307
+ import { appRoutes } from './app.routes';
308
+ import { ApplicationConfig } from '@angular/core';
309
+
310
+ export const appConfig: ApplicationConfig = {
311
+ providers: [
312
+ provideRouter(appRoutes),
313
+ provideTitleConfig({
314
+ // Prefix can be a static string...
315
+ // prefix: 'My Awesome App | '
316
+
317
+ // ...or a function for more control over the format
318
+ prefix: (title) => (title ? `${title} - MyApp` : 'MyApp'),
319
+ }),
320
+ ],
321
+ };
322
+ ```