docs(router): Clearly document how to retrieve all params in the router tree (#40306)
This commit documents how to add a helper function which combines all the params in the router state tree into a single object. It provides a starting point for developers to reference if they require a more fine-tuned approach. Fixes #11023 PR Close #40306
This commit is contained in:
parent
e05ac395fc
commit
b36bece17c
|
@ -298,7 +298,25 @@ export class ActivatedRouteSnapshot {
|
||||||
constructor(
|
constructor(
|
||||||
/** The URL segments matched by this route */
|
/** The URL segments matched by this route */
|
||||||
public url: UrlSegment[],
|
public url: UrlSegment[],
|
||||||
/** The matrix parameters scoped to this route */
|
/**
|
||||||
|
* The matrix parameters scoped to this route.
|
||||||
|
*
|
||||||
|
* You can compute all params (or data) in the router state or to get params outside
|
||||||
|
* of an activated component by traversing the `RouterState` tree as in the following
|
||||||
|
* example:
|
||||||
|
* ```
|
||||||
|
* collectRouteParams(router: Router) {
|
||||||
|
* let params = {};
|
||||||
|
* let stack: ActivatedRouteSnapshot[] = [router.routerState.snapshot.root];
|
||||||
|
* while (stack.length > 0) {
|
||||||
|
* const route = stack.pop()!;
|
||||||
|
* params = {...params, ...route.params};
|
||||||
|
* stack.push(...route.children);
|
||||||
|
* }
|
||||||
|
* return params;
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
public params: Params,
|
public params: Params,
|
||||||
/** The query parameters shared by all the routes */
|
/** The query parameters shared by all the routes */
|
||||||
public queryParams: Params,
|
public queryParams: Params,
|
||||||
|
|
Loading…
Reference in New Issue