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
4 changes: 2 additions & 2 deletions modules/angular2/src/router/route_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ export class RouteRegistry {
}
lastInstructionIsTerminal = lastInstruction.component.terminal;
}
if (!lastInstructionIsTerminal) {
if (isPresent(componentCursor) && !lastInstructionIsTerminal) {
throw new BaseException(
`Link "${ListWrapper.toJSON(linkParams)}" does not resolve to a terminal instruction.`);
`Link "${ListWrapper.toJSON(linkParams)}" does not resolve to a terminal or async instruction.`);
}
}

Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ export class Router {
_settleInstruction(instruction: Instruction): Promise<any> {
var unsettledInstructions: Array<Promise<any>> = [];
if (isBlank(instruction.component.componentType)) {
unsettledInstructions.push(instruction.component.resolveComponentType());
unsettledInstructions.push(instruction.component.resolveComponentType().then(
(type: Type) => { this.registry.configFromComponent(type); }));
}
if (isPresent(instruction.child)) {
unsettledInstructions.push(this._settleInstruction(instruction.child));
Expand Down
32 changes: 31 additions & 1 deletion modules/angular2/test/router/integration/router_link_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'angular2/test_lib';

import {NumberWrapper} from 'angular2/src/core/facade/lang';
import {PromiseWrapper} from 'angular2/src/core/facade/async';

import {bind, Component, DirectiveResolver, View} from 'angular2/core';

Expand All @@ -29,6 +30,7 @@ import {
Pipeline,
RouterLink,
RouterOutlet,
AsyncRoute,
Route,
RouteParams,
RouteConfig,
Expand Down Expand Up @@ -96,7 +98,6 @@ export function main() {
}));



it('should generate link hrefs with params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [router-link]="[\'./user\', {name: name}]">{{name}}</a>')
.then((_) => router.config(
Expand Down Expand Up @@ -128,6 +129,31 @@ export function main() {
});
}));

it('should generate link hrefs when asynchronously loaded',
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => router.config([
new AsyncRoute({
path: '/child-with-grandchild/...',
loader: parentCmpLoader,
as: 'child-with-grandchild'
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.

didn't you want to start following CamelCase name conventions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm going to make the naming convention enforced. I'd rather do all of the changes in one commit than have them be temporarily inconsistent.

})
]))
.then((_) => {
// TODO: refactor when https://github.com/angular/angular/pull/4074 lands
var instruction = router.generate(['/child-with-grandchild']);
return router.navigateInstruction(instruction);
})
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(
rootTC.componentViewChildren[1].componentViewChildren[0].nativeElement,
'href'))
.toEqual('/child-with-grandchild/grandchild');
async.done();
});
}));

it('should generate relative links preserving the existing parent route',
inject([AsyncTestCompleter], (async) => {
compile()
Expand Down Expand Up @@ -319,6 +345,10 @@ class HelloCmp {
class Hello2Cmp {
}

function parentCmpLoader() {
return PromiseWrapper.resolve(ParentCmp);
}

@Component({selector: 'parent-cmp'})
@View({
template: `{ <a [router-link]="['./grandchild']" class="grandchild-link">Grandchild</a>
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/router/route_registry_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function main() {
registry.config(RootHostCmp,
new Route({path: '/first/...', component: DummyParentCmp, as: 'first'}));
expect(() => { registry.generate(['first'], RootHostCmp); })
.toThrowError('Link "["first"]" does not resolve to a terminal instruction.');
.toThrowError('Link "["first"]" does not resolve to a terminal or async instruction.');
});

it('should match matrix params on child components and query params on the root component',
Expand Down
X Tutup