diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index 41b5cf7fa2..4227fcd203 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -389,9 +389,6 @@ export class Router { if (processCurrentUrl) { return of (t).pipe( - // Update URL if in `eager` update mode - tap(t => this.urlUpdateStrategy === 'eager' && !t.extras.skipLocationChange && - this.setBrowserUrl(t.rawUrl, !!t.extras.replaceUrl, t.id)), // Fire NavigationStart event switchMap(t => { const transition = this.transitions.getValue(); @@ -416,6 +413,10 @@ export class Router { this.rootComponentType, this.config, (url) => this.serializeUrl(url), this.paramsInheritanceStrategy, this.relativeLinkResolution), + // Update URL if in `eager` update mode + tap(t => this.urlUpdateStrategy === 'eager' && !t.extras.skipLocationChange && + this.setBrowserUrl(t.urlAfterRedirects, !!t.extras.replaceUrl, t.id)), + // Fire RoutesRecognized tap(t => { const routesRecognized = new RoutesRecognized( diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 9c62f6e47e..a8d94d8549 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -578,6 +578,41 @@ describe('Integration', () => { expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]'); }))); + fixmeIvy('FW-???: Error: ExpressionChangedAfterItHasBeenCheckedError') && + it('should eagerly update URL after redirects are applied with urlUpdateStrategy="eagar"', + fakeAsync(inject([Router, Location], (router: Router, location: Location) => { + const fixture = TestBed.createComponent(RootCmp); + advance(fixture); + + router.resetConfig([{path: 'team/:id', component: TeamCmp}]); + + router.navigateByUrl('/team/22'); + advance(fixture); + expect(location.path()).toEqual('/team/22'); + + expect(fixture.nativeElement).toHaveText('team 22 [ , right: ]'); + + router.urlUpdateStrategy = 'eager'; + + let urlAtNavStart = ''; + let urlAtRoutesRecognized = ''; + router.events.subscribe(e => { + if (e instanceof NavigationStart) { + urlAtNavStart = location.path(); + } + if (e instanceof RoutesRecognized) { + urlAtRoutesRecognized = location.path(); + } + }); + + router.navigateByUrl('/team/33'); + + advance(fixture); + expect(urlAtNavStart).toBe('/team/22'); + expect(urlAtRoutesRecognized).toBe('/team/33'); + expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]'); + }))); + fixmeIvy('FW-???: Error: ExpressionChangedAfterItHasBeenCheckedError') && it('should navigate back and forward', fakeAsync(inject([Router, Location], (router: Router, location: Location) => {