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

Function getInherited

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

Source from the content-addressed store, hash-verified

320 * route is component-less.
321 */
322export function getInherited(
323 route: ActivatedRouteSnapshot,
324 parent: ActivatedRouteSnapshot | null,
325 paramsInheritanceStrategy: ParamsInheritanceStrategy,
326): Inherited {
327 let inherited: Inherited;
328 const {routeConfig} = route;
329 if (
330 parent !== null &&
331 (paramsInheritanceStrategy === 'always' ||
332 // inherit parent data if route is empty path
333 routeConfig?.path === '' ||
334 // inherit parent data if parent was componentless
335 (!parent.component && !parent.routeConfig?.loadComponent))
336 ) {
337 inherited = {
338 // Reuse the parent's frozen params when the route adds none of its own.
339 params:
340 Object.keys(route.params).length === 0
341 ? parent.params
342 : Object.freeze({...parent.params, ...route.params}),
343 data: Object.freeze({...parent.data, ...route.data}),
344 resolve: {
345 // Snapshots are created with data inherited from parent and guards (i.e. canActivate) can
346 // change data because it's not frozen...
347 // This first line could be deleted chose to break/disallow mutating the `data` object in
348 // guards.
349 // Note that data from parents still override this mutated data so anyone relying on this
350 // might be surprised that it doesn't work if parent data is inherited but otherwise does.
351 ...route.data,
352 // Ensure inherited resolved data overrides inherited static data
353 ...parent.data,
354 // static data from the current route overrides any inherited data
355 ...routeConfig?.data,
356 // resolved data from current route overrides everything
357 ...route._resolvedData,
358 },
359 };
360 } else {
361 inherited = {
362 params: Object.freeze({...route.params}),
363 data: Object.freeze({...route.data}),
364 resolve: {...route.data, ...(route._resolvedData ?? {})},
365 };
366 }
367
368 if (routeConfig && hasStaticTitle(routeConfig)) {
369 inherited.resolve[RouteTitleKey] = routeConfig.title;
370 }
371 return inherited;
372}
373
374/**
375 * @description

Callers 3

createSnapshotMethod · 0.90
resolveDataFunction · 0.90
runResolveFunction · 0.90

Calls 2

hasStaticTitleFunction · 0.85
keysMethod · 0.65

Tested by

no test coverage detected