@@ -34,7 +34,6 @@ import type {NavigationTransition} from '../navigation_transition';
3434import type { ActivatedRouteSnapshot , RouterStateSnapshot } from '../router_state' ;
3535import { UrlSegment , UrlSerializer } from '../url_tree' ;
3636import { wrapIntoObservable } from '../utils/collection' ;
37- import { getClosestRouteInjector } from '../utils/config' ;
3837import {
3938 CanActivate ,
4039 CanDeactivate ,
@@ -54,7 +53,6 @@ import {prioritizedGuardValue} from './prioritized_guard_value';
5453import { takeUntilAbort } from '../utils/abort_signal_to_observable' ;
5554
5655export function checkGuards (
57- injector : EnvironmentInjector ,
5856 forwardEvent ?: ( evt : Event ) => void ,
5957) : MonoTypeOperatorFunction < NavigationTransition > {
6058 return mergeMap ( ( t ) => {
@@ -67,15 +65,10 @@ export function checkGuards(
6765 return of ( { ...t , guardsResult : true } ) ;
6866 }
6967
70- return runCanDeactivateChecks (
71- canDeactivateChecks ,
72- targetSnapshot ! ,
73- currentSnapshot ,
74- injector ,
75- ) . pipe (
68+ return runCanDeactivateChecks ( canDeactivateChecks , targetSnapshot ! , currentSnapshot ) . pipe (
7669 mergeMap ( ( canDeactivate ) => {
7770 return canDeactivate && isBoolean ( canDeactivate )
78- ? runCanActivateChecks ( targetSnapshot ! , canActivateChecks , injector , forwardEvent )
71+ ? runCanActivateChecks ( targetSnapshot ! , canActivateChecks , forwardEvent )
7972 : of ( canDeactivate ) ;
8073 } ) ,
8174 map ( ( guardsResult ) => ( { ...t , guardsResult} ) ) ,
@@ -87,12 +80,9 @@ function runCanDeactivateChecks(
8780 checks : CanDeactivate [ ] ,
8881 futureRSS : RouterStateSnapshot ,
8982 currRSS : RouterStateSnapshot ,
90- injector : EnvironmentInjector ,
9183) {
9284 return from ( checks ) . pipe (
93- mergeMap ( ( check ) =>
94- runCanDeactivate ( check . component , check . route , currRSS , futureRSS , injector ) ,
95- ) ,
85+ mergeMap ( ( check ) => runCanDeactivate ( check . component , check . route , currRSS , futureRSS ) ) ,
9686 first ( ( result ) => {
9787 return result !== true ;
9888 } , true ) ,
@@ -102,16 +92,15 @@ function runCanDeactivateChecks(
10292function runCanActivateChecks (
10393 futureSnapshot : RouterStateSnapshot ,
10494 checks : CanActivate [ ] ,
105- injector : EnvironmentInjector ,
10695 forwardEvent ?: ( evt : Event ) => void ,
10796) {
10897 return from ( checks ) . pipe (
10998 concatMap ( ( check : CanActivate ) => {
11099 return concat (
111100 fireChildActivationStart ( check . route . parent , forwardEvent ) ,
112101 fireActivationStart ( check . route , forwardEvent ) ,
113- runCanActivateChild ( futureSnapshot , check . path , injector ) ,
114- runCanActivate ( futureSnapshot , check . route , injector ) ,
102+ runCanActivateChild ( futureSnapshot , check . path ) ,
103+ runCanActivate ( futureSnapshot , check . route ) ,
115104 ) ;
116105 } ) ,
117106 first ( ( result ) => {
@@ -159,14 +148,13 @@ function fireChildActivationStart(
159148function runCanActivate (
160149 futureRSS : RouterStateSnapshot ,
161150 futureARS : ActivatedRouteSnapshot ,
162- injector : EnvironmentInjector ,
163151) : Observable < GuardResult > {
164152 const canActivate = futureARS . routeConfig ? futureARS . routeConfig . canActivate : null ;
165153 if ( ! canActivate || canActivate . length === 0 ) return of ( true ) ;
166154
167155 const canActivateObservables = canActivate . map ( ( canActivate ) => {
168156 return defer ( ( ) => {
169- const closestInjector = getClosestRouteInjector ( futureARS ) ?? injector ;
157+ const closestInjector = futureARS . _environmentInjector ;
170158 const guard = getTokenOrFunctionIdentity < CanActivate > (
171159 canActivate as ProviderToken < CanActivate > ,
172160 closestInjector ,
@@ -185,7 +173,6 @@ function runCanActivate(
185173function runCanActivateChild (
186174 futureRSS : RouterStateSnapshot ,
187175 path : ActivatedRouteSnapshot [ ] ,
188- injector : EnvironmentInjector ,
189176) : Observable < GuardResult > {
190177 const futureARS = path [ path . length - 1 ] ;
191178
@@ -199,7 +186,7 @@ function runCanActivateChild(
199186 return defer ( ( ) => {
200187 const guardsMapped = d . guards . map (
201188 ( canActivateChild : CanActivateChildFn | ProviderToken < unknown > ) => {
202- const closestInjector = getClosestRouteInjector ( d . node ) ?? injector ;
189+ const closestInjector = d . node . _environmentInjector ;
203190 const guard = getTokenOrFunctionIdentity < { canActivateChild : CanActivateChildFn } > (
204191 canActivateChild ,
205192 closestInjector ,
@@ -223,12 +210,11 @@ function runCanDeactivate(
223210 currARS : ActivatedRouteSnapshot ,
224211 currRSS : RouterStateSnapshot ,
225212 futureRSS : RouterStateSnapshot ,
226- injector : EnvironmentInjector ,
227213) : Observable < GuardResult > {
228214 const canDeactivate = currARS && currARS . routeConfig ? currARS . routeConfig . canDeactivate : null ;
229215 if ( ! canDeactivate || canDeactivate . length === 0 ) return of ( true ) ;
230216 const canDeactivateObservables = canDeactivate . map ( ( c : any ) => {
231- const closestInjector = getClosestRouteInjector ( currARS ) ?? injector ;
217+ const closestInjector = currARS . _environmentInjector ;
232218 const guard = getTokenOrFunctionIdentity < any > ( c , closestInjector ) ;
233219 const guardVal = isCanDeactivate ( guard )
234220 ? guard . canDeactivate ( component , currARS , currRSS , futureRSS )
0 commit comments