X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/angular1_router/test/integration/navigation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div>inner { <div ng-outlet></div> }</div>',
$routeConfig: [
{ path: '/b', component: 'oneCmp' }
]
});

$router.config([
{ path: '/...', component: 'childCmp' }
]);
compile('<div>outer { <div ng-outlet></div> }</div>');

$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', {
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -465,7 +465,7 @@ export class RootRouter extends Router {
commit(instruction: Instruction, _skipLocationChange: boolean = false): Promise<any> {
var emitPath = instruction.toUrlPath();
var emitQuery = instruction.toUrlQuery();
if (emitPath.length > 0) {
if (emitPath.length > 0 && emitPath[0] !== '/') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we are allowed to do this without using some StringWrapper method?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with ts2dart and the online dartlang testbed and this is fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently we need to use != to compare the strings as in Dart equivalent strings are not always identical

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we file an issue in ts2dart to detect the unsupported code pattern so we don't fall victim to it again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emitPath = '/' + emitPath;
}
var promise = super.commit(instruction);
Expand Down
14 changes: 14 additions & 0 deletions modules/angular2/test/router/integration/navigation_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { <router-outlet></router-outlet> }')
.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 { <router-outlet></router-outlet> }')
.then((rtc) => {fixture = rtc})
Expand Down
X Tutup