Skip to content

Commit

Permalink
fix(router): fix regression where navigateByUrl promise didn't resolv…
Browse files Browse the repository at this point in the history
…e on CanLoad failure

Fixes angular#26284
  • Loading branch information
jasonaden committed Oct 15, 2018
1 parent b2db32b commit b6db444
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export class Router {
const navCancel =
new NavigationCancel(t.id, this.serializeUrl(t.extractedUrl), e.message);
eventsSubject.next(navCancel);
t.resolve(false);
/* All other errors should reset to the router's internal URL reference to the
* pre-error state. */
} else {
Expand Down
39 changes: 39 additions & 0 deletions packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,45 @@ describe('Integration', () => {
]);
})));

// Regression where navigateByUrl with false CanLoad no longer resolved `false` value on
// navigateByUrl promise: https://github.com/angular/angular/issues/26284
it('should resolve navigateByUrl promise after CanLoad executes',
fakeAsync(inject(
[Router, Location, NgModuleFactoryLoader],
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {

@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyLoadedComponent {
}

@NgModule({
declarations: [LazyLoadedComponent],
imports:
[RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
})
class LazyLoadedModule {
}

loader.stubbedModules = {lazy: LazyLoadedModule};
const fixture = createRoot(router, RootCmp);

router.resetConfig([
{path: 'lazy-false', canLoad: ['alwaysFalse'], loadChildren: 'lazy'},
{path: 'lazy-true', canLoad: ['alwaysTrue'], loadChildren: 'lazy'},
]);

let navFalseResult: any;
let navTrueResult: any;
router.navigateByUrl('/lazy-false').then(v => { navFalseResult = v; });
advance(fixture);
router.navigateByUrl('/lazy-true').then(v => { navTrueResult = v; });
advance(fixture);

expect(navFalseResult).toBe(false);
expect(navTrueResult).toBe(true);

})));

it('should execute CanLoad only once',
fakeAsync(inject(
[Router, Location, NgModuleFactoryLoader],
Expand Down

0 comments on commit b6db444

Please sign in to comment.