MCPcopy Create free account
hub / github.com/angular/angular / getInherited

Function getInherited

packages/router/src/router_state.ts:267–313  ·  view source on GitHub ↗
(
  route: ActivatedRouteSnapshot,
  parent: ActivatedRouteSnapshot | null,
  paramsInheritanceStrategy: ParamsInheritanceStrategy,
)

Source from the content-addressed store, hash-verified

265 * route is component-less.
266 */
267export function getInherited(
268 route: ActivatedRouteSnapshot,
269 parent: ActivatedRouteSnapshot | null,
270 paramsInheritanceStrategy: ParamsInheritanceStrategy,
271): Inherited {
272 let inherited: Inherited;
273 const {routeConfig} = route;
274 if (
275 parent !== null &&
276 (paramsInheritanceStrategy === 'always' ||
277 // inherit parent data if route is empty path
278 routeConfig?.path === '' ||
279 // inherit parent data if parent was componentless
280 (!parent.component && !parent.routeConfig?.loadComponent))
281 ) {
282 inherited = {
283 params: {...parent.params, ...route.params},
284 data: {...parent.data, ...route.data},
285 resolve: {
286 // Snapshots are created with data inherited from parent and guards (i.e. canActivate) can
287 // change data because it's not frozen...
288 // This first line could be deleted chose to break/disallow mutating the `data` object in
289 // guards.
290 // Note that data from parents still override this mutated data so anyone relying on this
291 // might be surprised that it doesn't work if parent data is inherited but otherwise does.
292 ...route.data,
293 // Ensure inherited resolved data overrides inherited static data
294 ...parent.data,
295 // static data from the current route overrides any inherited data
296 ...routeConfig?.data,
297 // resolved data from current route overrides everything
298 ...route._resolvedData,
299 },
300 };
301 } else {
302 inherited = {
303 params: {...route.params},
304 data: {...route.data},
305 resolve: {...route.data, ...(route._resolvedData ?? {})},
306 };
307 }
308
309 if (routeConfig && hasStaticTitle(routeConfig)) {
310 inherited.resolve[RouteTitleKey] = routeConfig.title;
311 }
312 return inherited;
313}
314
315/**
316 * @description

Callers 3

createSnapshotMethod · 0.90
resolveDataFunction · 0.90
runResolveFunction · 0.90

Calls 1

hasStaticTitleFunction · 0.85

Tested by

no test coverage detected