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

Function runCanMatchGuards

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

Source from the content-addressed store, hash-verified

278}
279
280export function runCanMatchGuards(
281 injector: EnvironmentInjector,
282 route: Route,
283 segments: UrlSegment[],
284 urlSerializer: UrlSerializer,
285 currentSnapshot: PartialMatchRouteSnapshot,
286 abortSignal: AbortSignal,
287): Observable<GuardResult> {
288 const canMatch = route.canMatch;
289 if (!canMatch || canMatch.length === 0) return of(true);
290
291 const canMatchObservables = canMatch.map((injectionToken) => {
292 const guard = getTokenOrFunctionIdentity(injectionToken as ProviderToken<any>, injector);
293 return callGuard(() =>
294 isCanMatch(guard)
295 ? guard.canMatch(route, segments, currentSnapshot)
296 : runInInjectionContext(injector, () =>
297 (guard as CanMatchFn)(route, segments, currentSnapshot),
298 ),
299 ).pipe(takeUntilAbort(abortSignal));
300 });
301
302 return of(canMatchObservables).pipe(prioritizedGuardValue(), redirectIfUrlTree(urlSerializer));
303}

Callers 1

matchWithChecksFunction · 0.90

Calls 9

isCanMatchFunction · 0.90
runInInjectionContextFunction · 0.90
takeUntilAbortFunction · 0.90
prioritizedGuardValueFunction · 0.90
callGuardFunction · 0.85
redirectIfUrlTreeFunction · 0.85
mapMethod · 0.80
canMatchMethod · 0.65

Tested by

no test coverage detected