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

Function runCanLoadGuards

packages/router/src/operators/check_guards.ts:231–255  ·  view source on GitHub ↗
(
  injector: EnvironmentInjector,
  route: Route,
  segments: UrlSegment[],
  urlSerializer: UrlSerializer,
  abortSignal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

229}
230
231export function runCanLoadGuards(
232 injector: EnvironmentInjector,
233 route: Route,
234 segments: UrlSegment[],
235 urlSerializer: UrlSerializer,
236 abortSignal?: AbortSignal,
237): Observable<boolean> {
238 // TODO: Remove `canLoad` check once removed from 3p.
239 const canLoad = (route as any).canLoad;
240 if (canLoad === undefined || canLoad.length === 0) {
241 return of(true);
242 }
243
244 const canLoadObservables = canLoad.map((injectionToken: any) => {
245 const guard = getTokenOrFunctionIdentity<any>(injectionToken, injector);
246 const obs$ = callGuard(() =>
247 isCanLoad(guard)
248 ? guard.canLoad(route, segments)
249 : runInInjectionContext(injector, () => (guard as CanLoadFn)(route, segments)),
250 );
251 return abortSignal ? obs$.pipe(takeUntilAbort(abortSignal)) : obs$;
252 });
253
254 return of(canLoadObservables).pipe(prioritizedGuardValue(), redirectIfUrlTree(urlSerializer));
255}
256
257/**
258 * Calls a guard right away, but delivers a synchronous throw as an observable error so that

Callers 1

getChildConfigMethod · 0.90

Calls 9

isCanLoadFunction · 0.90
runInInjectionContextFunction · 0.90
takeUntilAbortFunction · 0.90
prioritizedGuardValueFunction · 0.90
callGuardFunction · 0.85
redirectIfUrlTreeFunction · 0.85
mapMethod · 0.80
canLoadMethod · 0.65

Tested by

no test coverage detected