( injector: EnvironmentInjector, route: Route, segments: UrlSegment[], urlSerializer: UrlSerializer, abortSignal?: AbortSignal, )
| 229 | } |
| 230 | |
| 231 | export 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 |
no test coverage detected