From eb6fb5f87e12dd39f9ca9a28b7e0b5ee302e142c Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Tue, 28 Mar 2017 22:11:44 +0300 Subject: [PATCH] fix(router): should navigate to the same url when config changes Closes #15535 --- packages/router/src/router.ts | 5 +++-- packages/router/test/integration.spec.ts | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts index ee88cb6901..8ea9a118e2 100644 --- a/packages/router/src/router.ts +++ b/packages/router/src/router.ts @@ -313,7 +313,7 @@ export class Router { get events(): Observable { return this.routerEvents; } /** @internal */ - triggerEvent(e: Event) { this.routerEvents.next(e); } + triggerEvent(e: Event): void { this.routerEvents.next(e); } /** * Resets the configuration used for navigation and generating links. @@ -332,10 +332,11 @@ export class Router { resetConfig(config: Routes): void { validateConfig(config); this.config = config; + this.navigated = false; } /** @docsNotRequired */ - ngOnDestroy() { this.dispose(); } + ngOnDestroy(): void { this.dispose(); } /** Disposes of the router */ dispose(): void { diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 62f686fb4a..d73be5fef8 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -398,6 +398,25 @@ describe('Integration', () => { expect(location.path()).toEqual('/team/22/user/victor'); }))); + it('should navigate to the same url when config changes', + fakeAsync(inject([Router, Location], (router: Router, location: Location) => { + const fixture = createRoot(router, RootCmp); + + router.resetConfig([{path: 'a', component: SimpleCmp}]); + + router.navigate(['/a']); + advance(fixture); + expect(location.path()).toEqual('/a'); + expect(fixture.nativeElement).toHaveText('simple'); + + router.resetConfig([{path: 'a', component: RouteCmp}]); + + router.navigate(['/a']); + advance(fixture); + expect(location.path()).toEqual('/a'); + expect(fixture.nativeElement).toHaveText('route'); + }))); + it('should navigate when locations changes', fakeAsync(inject([Router, Location], (router: Router, location: Location) => { const fixture = createRoot(router, RootCmp);