diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index 1f656360254..791e2dd91ec 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -715,14 +715,9 @@ export class Router { tap(t => { if (this.urlUpdateStrategy === 'eager') { if (!t.extras.skipLocationChange) { - this.setBrowserUrl(t.urlAfterRedirects, t); - // TODO(atscott): The above line is incorrect. It sets the url to - // only the part that is handled by the router. It should merge - // that with the rawUrl so the url includes segments not handled - // by the router: - // const rawUrl = this.urlHandlingStrategy.merge( - // t.urlAfterRedirects, t.rawUrl); - // this.setBrowserUrl(rawUrl, t); + const rawUrl = this.urlHandlingStrategy.merge( + t.urlAfterRedirects, t.rawUrl); + this.setBrowserUrl(rawUrl, t); } this.browserUrlTree = t.urlAfterRedirects; } diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 611194e4870..8260192a160 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -5647,28 +5647,23 @@ describe('Integration', () => { ]); }))); - it('should not reset parts of the URL not handled by the router', fakeAsync(() => { - const location = TestBed.inject(Location) as SpyLocation; + it('should not remove parts of the URL that are not handled by the router when "eager"', + fakeAsync(() => { const router = TestBed.inject(Router); + router.urlUpdateStrategy = 'eager'; + const location = TestBed.inject(Location) as SpyLocation; const fixture = createRoot(router, RootCmp); router.resetConfig([{ path: 'include', component: TeamCmp, - children: - [{path: 'user/:name', component: UserCmp}, {path: 'simple', component: SimpleCmp}] + children: [{path: 'user/:name', component: UserCmp}] }]); - try { - location.simulateHashChange('/include/butThisPartNotFound(aux:excluded)'); - advance(fixture); - } catch (e) { - } - // The router only handled the primary URL. So it processes the navigation and then - // cannot match the `butThisPartNotFound` part to a URL, throws an error, and then - // resets the state in the `catchError` block. The excluded part of the URL _should not_ - // be reset because it might be handled by another application. - expect(location.path()).toEqual('/(aux:excluded)'); + location.simulateHashChange('/include/user/kate(aux:excluded)'); + advance(fixture); + + expect(location.path()).toEqual('/include/user/kate(aux:excluded)'); })); });