fix(router): fix CanActivate redirect to the root on initial load (#13929)
Closes #13530 PR Close #13929
This commit is contained in:
parent
029f558d45
commit
e075b1ba83
|
@ -757,8 +757,8 @@ export class Router {
|
|||
})
|
||||
.then(
|
||||
() => {
|
||||
this.navigated = true;
|
||||
if (navigationIsSuccessful) {
|
||||
this.navigated = true;
|
||||
this.routerEvents.next(new NavigationEnd(
|
||||
id, this.serializeUrl(url), this.serializeUrl(this.currentUrlTree)));
|
||||
resolvePromise(true);
|
||||
|
|
|
@ -1442,6 +1442,35 @@ describe('Integration', () => {
|
|||
|
||||
})));
|
||||
});
|
||||
|
||||
describe('should redirect to / when guard returns false', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({
|
||||
providers: [{
|
||||
provide: 'returnFalseAndNavigate',
|
||||
useFactory: (router: Router) => () => {
|
||||
router.navigate(['/']);
|
||||
return false;
|
||||
},
|
||||
deps: [Router]
|
||||
}]
|
||||
}));
|
||||
|
||||
it('works', fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
router.resetConfig([
|
||||
{
|
||||
path: '',
|
||||
component: SimpleCmp,
|
||||
},
|
||||
{path: 'one', component: RouteCmp, canActivate: ['returnFalseAndNavigate']}
|
||||
]);
|
||||
|
||||
const fixture = TestBed.createComponent(RootCmp);
|
||||
router.navigateByUrl('/one');
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/');
|
||||
expect(fixture.nativeElement).toHaveText('simple');
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
||||
describe('CanDeactivate', () => {
|
||||
|
|
Loading…
Reference in New Issue