feat(router): add "paramsInheritanceStrategy" router configuration option
Previously, the router would merge path and matrix params, as well as data/resolve, with special rules (only merging down when the route has an empty path, or is component-less). This change adds an extra option "paramsInheritanceStrategy" which, when set to 'always', makes child routes unconditionally inherit params from parent routes. Closes #20572.
This commit is contained in:

committed by
Alex Rickabaugh

parent
5f23a1223f
commit
5efea2f6a0
@ -27,7 +27,7 @@ import {recognize} from './recognize';
|
||||
import {DefaultRouteReuseStrategy, DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
import {ChildrenOutletContexts} from './router_outlet_context';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState} from './router_state';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState, inheritedParamsDataResolve} from './router_state';
|
||||
import {Params, isNavigationCancelingError} from './shared';
|
||||
import {DefaultUrlHandlingStrategy, UrlHandlingStrategy} from './url_handling_strategy';
|
||||
import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tree';
|
||||
@ -249,6 +249,16 @@ export class Router {
|
||||
*/
|
||||
onSameUrlNavigation: 'reload'|'ignore' = 'ignore';
|
||||
|
||||
/**
|
||||
* Defines how the router merges params, data and resolved data from parent to child
|
||||
* routes. Available options are:
|
||||
*
|
||||
* - `'emptyOnly'`, the default, only inherits parent params for path-less or component-less
|
||||
* routes.
|
||||
* - `'always'`, enables unconditional inheritance of parent params.
|
||||
*/
|
||||
paramsInheritanceStrategy: 'emptyOnly'|'always' = 'emptyOnly';
|
||||
|
||||
/**
|
||||
* Creates the router service.
|
||||
*/
|
||||
@ -611,7 +621,8 @@ export class Router {
|
||||
urlAndSnapshot$ = mergeMap.call(redirectsApplied$, (appliedUrl: UrlTree) => {
|
||||
return map.call(
|
||||
recognize(
|
||||
this.rootComponentType, this.config, appliedUrl, this.serializeUrl(appliedUrl)),
|
||||
this.rootComponentType, this.config, appliedUrl, this.serializeUrl(appliedUrl),
|
||||
this.paramsInheritanceStrategy),
|
||||
(snapshot: any) => {
|
||||
|
||||
(this.events as Subject<Event>)
|
||||
@ -667,7 +678,7 @@ export class Router {
|
||||
if (p.shouldActivate && preActivation.isActivating()) {
|
||||
this.triggerEvent(
|
||||
new ResolveStart(id, this.serializeUrl(url), p.appliedUrl, p.snapshot));
|
||||
return map.call(preActivation.resolveData(), () => {
|
||||
return map.call(preActivation.resolveData(this.paramsInheritanceStrategy), () => {
|
||||
this.triggerEvent(
|
||||
new ResolveEnd(id, this.serializeUrl(url), p.appliedUrl, p.snapshot));
|
||||
return p;
|
||||
|
Reference in New Issue
Block a user