From 5e2ed0512da007ed1a70e4a8acd4fbca73bed5a1 Mon Sep 17 00:00:00 2001 From: Alexander Bachmann Date: Wed, 27 Jan 2016 21:05:34 +0100 Subject: [PATCH] This change fixes the pushState Problem Added unit test for angular2 router test suite This is the the second unit test for the #6729 pull request, which in turn is a fix for the #5502 issue This change fixes the pushState Problem Added unit test for angular2 router test suite This is the the second unit test for the #6729 pull request, which in turn is a fix for the #5502 issue Squashing some commits --- .../test/integration/navigation_spec.js | 20 +++++++++++++++++++ modules/angular2/src/router/router.ts | 4 ++-- .../router/integration/navigation_spec.ts | 14 +++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/angular1_router/test/integration/navigation_spec.js b/modules/angular1_router/test/integration/navigation_spec.js index 3d230c4b1290..8842fbc078ac 100644 --- a/modules/angular1_router/test/integration/navigation_spec.js +++ b/modules/angular1_router/test/integration/navigation_spec.js @@ -112,6 +112,26 @@ describe('navigation', function () { expect(elt.text()).toBe('outer { inner { one } }'); }); + it('should work when parent route has empty path', inject(function ($location) { + registerComponent('childCmp', { + template: '
inner {
}
', + $routeConfig: [ + { path: '/b', component: 'oneCmp' } + ] + }); + + $router.config([ + { path: '/...', component: 'childCmp' } + ]); + compile('
outer {
}
'); + + $router.navigateByUrl('/b'); + $rootScope.$digest(); + + expect(elt.text()).toBe('outer { inner { one } }'); + expect($location.path()).toBe('/b'); + })); + it('should work with recursive nested outlets', function () { registerComponent('recurCmp', { diff --git a/modules/angular2/src/router/router.ts b/modules/angular2/src/router/router.ts index a1bd9b041606..2dc8cf9e3482 100644 --- a/modules/angular2/src/router/router.ts +++ b/modules/angular2/src/router/router.ts @@ -438,7 +438,7 @@ export class RootRouter extends Router { } var emitPath = instruction.toUrlPath(); var emitQuery = instruction.toUrlQuery(); - if (emitPath.length > 0) { + if (emitPath.length > 0 && emitPath[0] !== '/') { emitPath = '/' + emitPath; } @@ -465,7 +465,7 @@ export class RootRouter extends Router { commit(instruction: Instruction, _skipLocationChange: boolean = false): Promise { var emitPath = instruction.toUrlPath(); var emitQuery = instruction.toUrlQuery(); - if (emitPath.length > 0) { + if (emitPath.length > 0 && emitPath[0] !== '/') { emitPath = '/' + emitPath; } var promise = super.commit(instruction); diff --git a/modules/angular2/test/router/integration/navigation_spec.ts b/modules/angular2/test/router/integration/navigation_spec.ts index 8e649ec9c26e..99b99c255ff6 100644 --- a/modules/angular2/test/router/integration/navigation_spec.ts +++ b/modules/angular2/test/router/integration/navigation_spec.ts @@ -105,6 +105,20 @@ export function main() { }); })); + it('should navigate to child routes when the root component has an empty path', + inject([AsyncTestCompleter, Location], (async, location) => { + compile(tcb, 'outer { }') + .then((rtc) => {fixture = rtc}) + .then((_) => rtr.config([new Route({path: '/...', component: ParentCmp})])) + .then((_) => rtr.navigateByUrl('/b')) + .then((_) => { + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }'); + expect(location.urlChanges).toEqual(['/b']); + async.done(); + }); + })); + it('should navigate to child routes of async routes', inject([AsyncTestCompleter], (async) => { compile(tcb, 'outer { }') .then((rtc) => {fixture = rtc})