Skip to content

Commit 774fad4

Browse files
authored
feat: expose the MinimalRouteData type (#299)
# Features - Expose the `MinmalRouteData` type used by `MinimalActivatedRouteSnapshot#data`.
1 parent d4dadf0 commit 774fad4

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Published with partial Ivy compilation.
1717

1818
## API
1919

20-
A `RouterStore` service has the following public properties:
20+
### RouterStore
21+
22+
A `RouterStore` service has the following public properties.
2123

2224
| API | Description |
2325
| ----------------------------------------------------------------------- | ------------------------------------------ |
@@ -40,7 +42,7 @@ A _local_ `RouterStore` requires a component-level provider, follows the
4042
lifecycle of that component, and can be injected in declarables as well as
4143
other component-level services.
4244

43-
### Global router store
45+
#### Global router store
4446

4547
An application-wide router store that can be injected in any class. Use
4648
`provideGlobalRouterStore` to provide it in a root environment injector.
@@ -107,7 +109,7 @@ export class HeroDetailComponent {
107109
}
108110
```
109111

110-
### Local router store
112+
#### Local router store
111113

112114
A component-level router store. Can be injected in any directive, component,
113115
pipe, or component-level service. Explicitly provided in a component sub-tree
@@ -134,3 +136,34 @@ export class HeroDetailComponent {
134136
this.#routerStore.selectRouteParam('id');
135137
}
136138
```
139+
140+
### Serializable router state
141+
142+
Several of the Angular Router's types are recursive which means that they aren't serializable. The router stores exclusively use serializable types to support advanced state synchronization strategies.
143+
144+
#### MinimalActivatedRouteSnapshot
145+
146+
The `MinimalActivatedRouteSnapshot` interface is used for the observable `RouterStore#currentRoute$` property. This interface is a serializable subset of the Angular Router's `ActivatedRouteSnapshot` class and has the following public properties.
147+
148+
| API | Description |
149+
| --------------------------------------------------- | ------------------------------------------------ |
150+
| `children: MinimalActivatedRouteSnapshot[]` | The children of this route in the route tree. |
151+
| `data: MinimalRouteData` | The static and resolved data of this route. |
152+
| `firstChild: MinimalActivatedRouteSnapshot \| null` | The first child of this route in the route tree. |
153+
| `fragment: string \| null` | The URL fragment shared by all routes. |
154+
| `outlet: string` | The outlet name of the route. |
155+
| `params: Params` | The matrix parameters scoped to this route. |
156+
| `queryParams: Params` | The query parameters shared by all routes. |
157+
| `routeConfig: Route \| null` | The configuration used to match this route. |
158+
| `title: string \| undefined` | The resolved route title. |
159+
| `url: UrlSegment[]` | The URL segments matched by this route. |
160+
161+
#### MinimalRouteData
162+
163+
The `MinimalRouteData` interface is used for the `RouterStore#data$` property. This interface is a serializable subset of the Angular Router's `Data` type. In particular, the `symbol` index in the Angular Router's `Data` type is removed. `MinimalRouteData` has the following signature.
164+
165+
```typescript
166+
export type MinimalRouteData = {
167+
[key: string]: any;
168+
};
169+
```

packages/router-component-store/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './lib/router-store';
99

1010
// Serializable route state
1111
export * from './lib/@ngrx/router-store/minimal-activated-route-state-snapshot';
12+
export * from './lib/minimal-route-data';

packages/router-component-store/src/lib/@ngrx/router-store/minimal-activated-route-state-snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* found in the LICENSE file at https://angular.io/license
3131
*/
3232
import { ActivatedRouteSnapshot } from '@angular/router';
33-
import { OmitSymbolIndex } from '../../util-types/omit-symbol-index';
33+
import { MinimalRouteData } from '../../minimal-route-data';
3434

3535
/**
3636
* Contains the information about a route associated with a component loaded in
@@ -67,7 +67,7 @@ export interface MinimalActivatedRouteSnapshot {
6767
* the Angular `Router`. Instead, we access the resolved route title through
6868
* `MinimalActivatedRouteSnapshot['title']`.
6969
*/
70-
readonly data: OmitSymbolIndex<ActivatedRouteSnapshot['data']>;
70+
readonly data: MinimalRouteData;
7171
/**
7272
* The outlet name of the route.
7373
*/

packages/router-component-store/src/lib/minimal-route-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { OmitSymbolIndex } from './util-types/omit-symbol-index';
33

44
/**
55
* Serializable route `Data` without its symbol index, in particular without the
6-
* `Symbol.for(RouteTitle)` key as this is an internal value for the Angular
6+
* `Symbol(RouteTitle)` key as this is an internal value for the Angular
77
* `Router`.
88
*/
99
export type MinimalRouteData = OmitSymbolIndex<Data>;

0 commit comments

Comments
 (0)