@@ -286,10 +286,40 @@ describe('integration spec', () => {
286286 done ( ) ;
287287 } ) ;
288288 } ) ;
289+
290+ it ( 'should support cancellation of initial navigation using canLoad guard' , done => {
291+ const reducer = ( state : any , action : RouterAction < any > ) => {
292+ const r = routerReducer ( state , action ) ;
293+ return r && r . state
294+ ? { url : r . state . url , navigationId : r . navigationId }
295+ : null ;
296+ } ;
297+
298+ createTestModule ( {
299+ reducers : { routerReducer, reducer } ,
300+ canLoad : ( ) => false ,
301+ } ) ;
302+
303+ const router = TestBed . get ( Router ) ;
304+ const store = TestBed . get ( Store ) ;
305+ const log = logOfRouterAndStore ( router , store ) ;
306+
307+ router . navigateByUrl ( '/load' ) . then ( ( r : boolean ) => {
308+ expect ( r ) . toBe ( false ) ;
309+
310+ expect ( log ) . toEqual ( [
311+ { type : 'store' , state : null } ,
312+ { type : 'router' , event : 'NavigationStart' , url : '/load' } ,
313+ { type : 'store' , state : null } ,
314+ { type : 'router' , event : 'NavigationCancel' , url : '/load' } ,
315+ ] ) ;
316+ done ( ) ;
317+ } ) ;
318+ } ) ;
289319} ) ;
290320
291321function createTestModule (
292- opts : { reducers ?: any ; canActivate ?: Function } = { }
322+ opts : { reducers ?: any ; canActivate ?: Function ; canLoad ?: Function } = { }
293323) {
294324 @Component ( {
295325 selector : 'test-app' ,
@@ -314,6 +344,11 @@ function createTestModule(
314344 component : SimpleCmp ,
315345 canActivate : [ 'CanActivateNext' ] ,
316346 } ,
347+ {
348+ path : 'load' ,
349+ loadChildren : 'test' ,
350+ canLoad : [ 'CanLoadNext' ] ,
351+ } ,
317352 ] ) ,
318353 StoreRouterConnectingModule ,
319354 ] ,
@@ -322,6 +357,10 @@ function createTestModule(
322357 provide : 'CanActivateNext' ,
323358 useValue : opts . canActivate || ( ( ) => true ) ,
324359 } ,
360+ {
361+ provide : 'CanLoadNext' ,
362+ useValue : opts . canLoad || ( ( ) => true ) ,
363+ } ,
325364 ] ,
326365 } ) ;
327366
0 commit comments