Skip to content

Commit 99960a9

Browse files
jbogarthydeAndrewKushnir
authored andcommitted
docs: update router api documentation (angular#37980)
Edit descriptions, usage examples, and add links to be complete and consistent with API reference doc style PR Close angular#37980
1 parent 9ac3383 commit 99960a9

File tree

6 files changed

+221
-129
lines changed

6 files changed

+221
-129
lines changed

goldens/public-api/router/router.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ export declare class GuardsCheckStart extends RouterEvent {
148148
toString(): string;
149149
}
150150

151-
/** @deprecated */
152151
export declare type InitialNavigation = true | false | 'enabled' | 'disabled' | 'legacy_enabled' | 'legacy_disabled';
153152

154153
export declare type LoadChildren = LoadChildrenCallback | DeprecatedLoadChildren;

packages/router/src/config.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
2222
*
2323
* @see `Route`
2424
* @see `Router`
25+
* @see [Router configuration guide](guide/router#configuration)
2526
* @publicApi
2627
*/
2728
export type Routes = Route[];
@@ -45,14 +46,12 @@ export type UrlMatchResult = {
4546
* for `Route.matcher` when a combination of `path` and `pathMatch`
4647
* is not expressive enough. Cannot be used together with `path` and `pathMatch`.
4748
*
48-
* @param segments An array of URL segments.
49-
* @param group A segment group.
50-
* @param route The route to match against.
51-
* @returns The match-result.
49+
* The function takes the following arguments and returns a `UrlMatchResult` object.
50+
* * *segments* : An array of URL segments.
51+
* * *group* : A segment group.
52+
* * *route* : The route to match against.
5253
*
53-
* @usageNotes
54-
*
55-
* The following matcher matches HTML files.
54+
* The following example implementation matches HTML files.
5655
*
5756
* ```
5857
* export function htmlFiles(url: UrlSegment[]) {
@@ -94,8 +93,10 @@ export type ResolveData = {
9493
/**
9594
*
9695
* A function that is called to resolve a collection of lazy-loaded routes.
96+
* Must be an arrow function of the following form:
97+
* `() => import('...').then(mod => mod.MODULE)`
9798
*
98-
* Often this function will be implemented using an ES dynamic `import()` expression. For example:
99+
* For example:
99100
*
100101
* ```
101102
* [{
@@ -104,35 +105,32 @@ export type ResolveData = {
104105
* }];
105106
* ```
106107
*
107-
* This function _must_ match the form above: an arrow function of the form
108-
* `() => import('...').then(mod => mod.MODULE)`.
109-
*
110-
* @see `Route#loadChildren`.
108+
* @see [Route.loadChildren](api/router/Route#loadChildren)
111109
* @publicApi
112110
*/
113111
export type LoadChildrenCallback = () => Type<any>|NgModuleFactory<any>|Observable<Type<any>>|
114112
Promise<NgModuleFactory<any>|Type<any>|any>;
115113

116114
/**
117115
*
118-
* A string of the form `path/to/file#exportName` that acts as a URL for a set of routes to load,
119-
* or a function that returns such a set.
116+
* A function that returns a set of routes to load.
120117
*
121118
* The string form of `LoadChildren` is deprecated (see `DeprecatedLoadChildren`). The function
122119
* form (`LoadChildrenCallback`) should be used instead.
123120
*
124-
* @see `Route#loadChildren`.
121+
* @see `loadChildrenCallback`
125122
* @publicApi
126123
*/
127124
export type LoadChildren = LoadChildrenCallback|DeprecatedLoadChildren;
128125

129126
/**
130127
* A string of the form `path/to/file#exportName` that acts as a URL for a set of routes to load.
131128
*
132-
* @see `Route#loadChildren`
129+
* @see `loadChildrenCallback`
133130
* @publicApi
134-
* @deprecated the `string` form of `loadChildren` is deprecated in favor of the proposed ES dynamic
135-
* `import()` expression, which offers a more natural and standards-based mechanism to dynamically
131+
* @deprecated The `string` form of `loadChildren` is deprecated in favor of the
132+
* `LoadChildrenCallback` function which uses the ES dynamic `import()` expression.
133+
* This offers a more natural and standards-based mechanism to dynamically
136134
* load an ES module at runtime.
137135
*/
138136
export type DeprecatedLoadChildren = string;
@@ -154,7 +152,7 @@ export type QueryParamsHandling = 'merge'|'preserve'|'';
154152
*
155153
* A policy for when to run guards and resolvers on a route.
156154
*
157-
* @see `Route#runGuardsAndResolvers`
155+
* @see [Route.runGuardsAndResolvers](api/router/Route#runGuardsAndResolvers)
158156
* @publicApi
159157
*/
160158
export type RunGuardsAndResolvers =
@@ -371,7 +369,8 @@ export type RunGuardsAndResolvers =
371369
*
372370
* Lazy loading speeds up application load time by splitting the application
373371
* into multiple bundles and loading them on demand.
374-
* To use lazy loading, provide the `loadChildren` property instead of the `children` property.
372+
* To use lazy loading, provide the `loadChildren` property in the `Route` object,
373+
* instead of the `children` property.
375374
*
376375
* Given the following example route, the router will lazy load
377376
* the associated module on demand using the browser native import system.
@@ -470,7 +469,7 @@ export interface Route {
470469
*/
471470
children?: Routes;
472471
/**
473-
* A `LoadChildren` object specifying lazy-loaded child routes.
472+
* An object specifying lazy-loaded child routes.
474473
*/
475474
loadChildren?: LoadChildren;
476475
/**

packages/router/src/events.ts

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type NavigationTrigger = 'imperative'|'popstate'|'hashchange';
2424
* Base for events the router goes through, as opposed to events tied to a specific
2525
* route. Fired one time for any given navigation.
2626
*
27-
* @usageNotes
27+
* The following code shows how a class subscribes to router events.
2828
*
2929
* ```ts
3030
* class MyService {
@@ -39,6 +39,7 @@ export type NavigationTrigger = 'imperative'|'popstate'|'hashchange';
3939
* ```
4040
*
4141
* @see `Event`
42+
* @see [Router events summary](guide/router#router-events)
4243
* @publicApi
4344
*/
4445
export class RouterEvent {
@@ -59,6 +60,9 @@ export class NavigationStart extends RouterEvent {
5960
* Identifies the call or event that triggered the navigation.
6061
* An `imperative` trigger is a call to `router.navigateByUrl()` or `router.navigate()`.
6162
*
63+
* @see `NavigationEnd`
64+
* @see `NavigationCancel`
65+
* @see `NavigationError`
6266
*/
6367
navigationTrigger?: 'imperative'|'popstate'|'hashchange';
6468

@@ -104,6 +108,10 @@ export class NavigationStart extends RouterEvent {
104108
/**
105109
* An event triggered when a navigation ends successfully.
106110
*
111+
* @see `NavigationStart`
112+
* @see `NavigationCancel`
113+
* @see `NavigationError`
114+
*
107115
* @publicApi
108116
*/
109117
export class NavigationEnd extends RouterEvent {
@@ -126,10 +134,13 @@ export class NavigationEnd extends RouterEvent {
126134

127135
/**
128136
* An event triggered when a navigation is canceled, directly or indirectly.
129-
*
130-
* This can happen when a [route guard](guide/router-tutorial-toh#milestone-5-route-guards)
137+
* This can happen when a route guard
131138
* returns `false` or initiates a redirect by returning a `UrlTree`.
132139
*
140+
* @see `NavigationStart`
141+
* @see `NavigationEnd`
142+
* @see `NavigationError`
143+
*
133144
* @publicApi
134145
*/
135146
export class NavigationCancel extends RouterEvent {
@@ -152,6 +163,10 @@ export class NavigationCancel extends RouterEvent {
152163
/**
153164
* An event triggered when a navigation fails due to an unexpected error.
154165
*
166+
* @see `NavigationStart`
167+
* @see `NavigationEnd`
168+
* @see `NavigationCancel`
169+
*
155170
* @publicApi
156171
*/
157172
export class NavigationError extends RouterEvent {
@@ -172,7 +187,7 @@ export class NavigationError extends RouterEvent {
172187
}
173188

174189
/**
175-
*An event triggered when routes are recognized.
190+
* An event triggered when routes are recognized.
176191
*
177192
* @publicApi
178193
*/
@@ -199,6 +214,8 @@ export class RoutesRecognized extends RouterEvent {
199214
/**
200215
* An event triggered at the start of the Guard phase of routing.
201216
*
217+
* @see `GuardsCheckEnd`
218+
*
202219
* @publicApi
203220
*/
204221
export class GuardsCheckStart extends RouterEvent {
@@ -223,6 +240,8 @@ export class GuardsCheckStart extends RouterEvent {
223240
/**
224241
* An event triggered at the end of the Guard phase of routing.
225242
*
243+
* @see `GuardsCheckStart`
244+
*
226245
* @publicApi
227246
*/
228247
export class GuardsCheckEnd extends RouterEvent {
@@ -252,6 +271,8 @@ export class GuardsCheckEnd extends RouterEvent {
252271
* Runs in the "resolve" phase whether or not there is anything to resolve.
253272
* In future, may change to only run when there are things to be resolved.
254273
*
274+
* @see `ResolveEnd`
275+
*
255276
* @publicApi
256277
*/
257278
export class ResolveStart extends RouterEvent {
@@ -301,6 +322,8 @@ export class ResolveEnd extends RouterEvent {
301322
/**
302323
* An event triggered before lazy loading a route configuration.
303324
*
325+
* @see `RouteConfigLoadEnd`
326+
*
304327
* @publicApi
305328
*/
306329
export class RouteConfigLoadStart {
@@ -315,6 +338,8 @@ export class RouteConfigLoadStart {
315338
/**
316339
* An event triggered when a route has been lazy loaded.
317340
*
341+
* @see `RouteConfigLoadStart`
342+
*
318343
* @publicApi
319344
*/
320345
export class RouteConfigLoadEnd {
@@ -348,7 +373,7 @@ export class ChildActivationStart {
348373
* An event triggered at the end of the child-activation part
349374
* of the Resolve phase of routing.
350375
* @see `ChildActivationStart`
351-
* @see `ResolveStart` *
376+
* @see `ResolveStart`
352377
* @publicApi
353378
*/
354379
export class ChildActivationEnd {
@@ -364,7 +389,7 @@ export class ChildActivationEnd {
364389
/**
365390
* An event triggered at the start of the activation part
366391
* of the Resolve phase of routing.
367-
* @see ActivationEnd`
392+
* @see `ActivationEnd`
368393
* @see `ResolveStart`
369394
*
370395
* @publicApi
@@ -422,24 +447,33 @@ export class Scroll {
422447
/**
423448
* Router events that allow you to track the lifecycle of the router.
424449
*
425-
* The sequence of router events is as follows:
426-
*
427-
* - `NavigationStart`,
428-
* - `RouteConfigLoadStart`,
429-
* - `RouteConfigLoadEnd`,
430-
* - `RoutesRecognized`,
431-
* - `GuardsCheckStart`,
432-
* - `ChildActivationStart`,
433-
* - `ActivationStart`,
434-
* - `GuardsCheckEnd`,
435-
* - `ResolveStart`,
436-
* - `ResolveEnd`,
437-
* - `ActivationEnd`
438-
* - `ChildActivationEnd`
439-
* - `NavigationEnd`,
440-
* - `NavigationCancel`,
441-
* - `NavigationError`
442-
* - `Scroll`
450+
* The events occur in the following sequence:
451+
*
452+
* * [NavigationStart](api/router/NavigationStart): Navigation starts.
453+
* * [RouteConfigLoadStart](api/router/RouteConfigLoadStart): Before
454+
* the router [lazy loads](/guide/router#lazy-loading) a route configuration.
455+
* * [RouteConfigLoadEnd](api/router/RouteConfigLoadEnd): After a route has been lazy loaded.
456+
* * [RoutesRecognized](api/router/RoutesRecognized): When the router parses the URL
457+
* and the routes are recognized.
458+
* * [GuardsCheckStart](api/router/GuardsCheckStart): When the router begins the *guards*
459+
* phase of routing.
460+
* * [ChildActivationStart](api/router/ChildActivationStart): When the router
461+
* begins activating a route's children.
462+
* * [ActivationStart](api/router/ActivationStart): When the router begins activating a route.
463+
* * [GuardsCheckEnd](api/router/GuardsCheckEnd): When the router finishes the *guards*
464+
* phase of routing successfully.
465+
* * [ResolveStart](api/router/ResolveStart): When the router begins the *resolve*
466+
* phase of routing.
467+
* * [ResolveEnd](api/router/ResolveEnd): When the router finishes the *resolve*
468+
* phase of routing successfuly.
469+
* * [ChildActivationEnd](api/router/ChildActivationEnd): When the router finishes
470+
* activating a route's children.
471+
* * [ActivationEnd](api/router/ActivationStart): When the router finishes activating a route.
472+
* * [NavigationEnd](api/router/NavigationEnd): When navigation ends successfully.
473+
* * [NavigationCancel](api/router/NavigationCancel): When navigation is canceled.
474+
* * [NavigationError](api/router/NavigationError): When navigation fails
475+
* due to an unexpected error.
476+
* * [Scroll](api/router/Scroll): When the user scrolls.
443477
*
444478
* @publicApi
445479
*/

0 commit comments

Comments
 (0)