@@ -14,7 +14,6 @@ import {
1414} from '@angular/common' ;
1515import {
1616 APP_BOOTSTRAP_LISTENER ,
17- APP_INITIALIZER ,
1817 ApplicationRef ,
1918 ComponentRef ,
2019 ENVIRONMENT_INITIALIZER ,
@@ -24,6 +23,7 @@ import {
2423 Injector ,
2524 makeEnvironmentProviders ,
2625 NgZone ,
26+ provideAppInitializer ,
2727 Provider ,
2828 runInInjectionContext ,
2929 Type ,
@@ -109,15 +109,15 @@ export function rootRoute(router: Router): ActivatedRoute {
109109 */
110110export interface RouterFeature < FeatureKind extends RouterFeatureKind > {
111111 ɵkind : FeatureKind ;
112- ɵproviders : Provider [ ] ;
112+ ɵproviders : Array < Provider | EnvironmentProviders > ;
113113}
114114
115115/**
116116 * Helper function to create an object that represents a Router feature.
117117 */
118118function routerFeature < FeatureKind extends RouterFeatureKind > (
119119 kind : FeatureKind ,
120- providers : Provider [ ] ,
120+ providers : Array < Provider | EnvironmentProviders > ,
121121) : RouterFeature < FeatureKind > {
122122 return { ɵkind : kind , ɵproviders : providers } ;
123123}
@@ -348,40 +348,34 @@ export type InitialNavigationFeature =
348348export function withEnabledBlockingInitialNavigation ( ) : EnabledBlockingInitialNavigationFeature {
349349 const providers = [
350350 { provide : INITIAL_NAVIGATION , useValue : InitialNavigation . EnabledBlocking } ,
351- {
352- provide : APP_INITIALIZER ,
353- multi : true ,
354- deps : [ Injector ] ,
355- useFactory : ( injector : Injector ) => {
356- const locationInitialized : Promise < any > = injector . get (
357- LOCATION_INITIALIZED ,
358- Promise . resolve ( ) ,
359- ) ;
360-
361- return ( ) => {
362- return locationInitialized . then ( ( ) => {
363- return new Promise ( ( resolve ) => {
364- const router = injector . get ( Router ) ;
365- const bootstrapDone = injector . get ( BOOTSTRAP_DONE ) ;
366- afterNextNavigation ( router , ( ) => {
367- // Unblock APP_INITIALIZER in case the initial navigation was canceled or errored
368- // without a redirect.
369- resolve ( true ) ;
370- } ) ;
371-
372- injector . get ( NavigationTransitions ) . afterPreactivation = ( ) => {
373- // Unblock APP_INITIALIZER once we get to `afterPreactivation`. At this point, we
374- // assume activation will complete successfully (even though this is not
375- // guaranteed).
376- resolve ( true ) ;
377- return bootstrapDone . closed ? of ( void 0 ) : bootstrapDone ;
378- } ;
379- router . initialNavigation ( ) ;
380- } ) ;
351+ provideAppInitializer ( ( ) => {
352+ const injector = inject ( Injector ) ;
353+ const locationInitialized : Promise < any > = injector . get (
354+ LOCATION_INITIALIZED ,
355+ Promise . resolve ( ) ,
356+ ) ;
357+
358+ return locationInitialized . then ( ( ) => {
359+ return new Promise ( ( resolve ) => {
360+ const router = injector . get ( Router ) ;
361+ const bootstrapDone = injector . get ( BOOTSTRAP_DONE ) ;
362+ afterNextNavigation ( router , ( ) => {
363+ // Unblock APP_INITIALIZER in case the initial navigation was canceled or errored
364+ // without a redirect.
365+ resolve ( true ) ;
381366 } ) ;
382- } ;
383- } ,
384- } ,
367+
368+ injector . get ( NavigationTransitions ) . afterPreactivation = ( ) => {
369+ // Unblock APP_INITIALIZER once we get to `afterPreactivation`. At this point, we
370+ // assume activation will complete successfully (even though this is not
371+ // guaranteed).
372+ resolve ( true ) ;
373+ return bootstrapDone . closed ? of ( void 0 ) : bootstrapDone ;
374+ } ;
375+ router . initialNavigation ( ) ;
376+ } ) ;
377+ } ) ;
378+ } ) ,
385379 ] ;
386380 return routerFeature ( RouterFeatureKind . EnabledBlockingInitialNavigationFeature , providers ) ;
387381}
@@ -426,16 +420,9 @@ export type DisabledInitialNavigationFeature =
426420 */
427421export function withDisabledInitialNavigation ( ) : DisabledInitialNavigationFeature {
428422 const providers = [
429- {
430- provide : APP_INITIALIZER ,
431- multi : true ,
432- useFactory : ( ) => {
433- const router = inject ( Router ) ;
434- return ( ) => {
435- router . setUpLocationChangeListener ( ) ;
436- } ;
437- } ,
438- } ,
423+ provideAppInitializer ( ( ) => {
424+ inject ( Router ) . setUpLocationChangeListener ( ) ;
425+ } ) ,
439426 { provide : INITIAL_NAVIGATION , useValue : InitialNavigation . Disabled } ,
440427 ] ;
441428 return routerFeature ( RouterFeatureKind . DisabledInitialNavigationFeature , providers ) ;
0 commit comments