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
24 changes: 22 additions & 2 deletions modules/angular2/src/router/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Promise, PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {Map, MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
import {Map, StringMapWrapper, MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
import {
isBlank,
isString,
Expand Down Expand Up @@ -131,7 +131,8 @@ export class Router {
}

_navigate(instruction: Instruction, _skipLocationChange: boolean): Promise<any> {
return this._reuse(instruction)
return this._settleInstruction(instruction)
.then((_) => this._reuse(instruction))
.then((_) => this._canActivate(instruction))
.then((result) => {
if (!result) {
Expand All @@ -150,6 +151,25 @@ export class Router {
});
}

// TODO(btford): it'd be nice to remove this method as part of cleaning up the traversal logic
// Since refactoring `Router.generate` to return an instruction rather than a string, it's not
// guaranteed that the `componentType`s for the terminal async routes have been loaded by the time
// we begin navigation. The method below simply traverses instructions and resolves any components
// for which `componentType` is not present
_settleInstruction(instruction: Instruction): Promise<any> {
var unsettledInstructions: List<Promise<any>> = [];
if (isBlank(instruction.component.componentType)) {
unsettledInstructions.push(instruction.component.resolveComponentType());
}
if (isPresent(instruction.child)) {
unsettledInstructions.push(this._settleInstruction(instruction.child));
}
StringMapWrapper.forEach(instruction.auxInstruction, (instruction, _) => {
unsettledInstructions.push(this._settleInstruction(instruction));
});
return PromiseWrapper.all(unsettledInstructions);
}

private _emitNavigationFinish(url): void { ObservableWrapper.callNext(this._subject, url); }

private _afterPromiseFinishNavigating(promise: Promise<any>): Promise<any> {
Expand Down
25 changes: 22 additions & 3 deletions modules/angular2/test/router/router_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
beforeEachBindings,
SpyObject
} from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/facade/lang';

import {IMPLEMENTS, Type} from 'angular2/src/facade/lang';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {ListWrapper} from 'angular2/src/facade/collection';

import {Router, RootRouter} from 'angular2/src/router/router';
import {Pipeline} from 'angular2/src/router/pipeline';
import {RouterOutlet} from 'angular2/src/router/router_outlet';
Expand All @@ -23,7 +23,7 @@ import {Location} from 'angular2/src/router/location';
import {stringifyInstruction} from 'angular2/src/router/instruction';

import {RouteRegistry} from 'angular2/src/router/route_registry';
import {RouteConfig, Route} from 'angular2/src/router/route_config_decorator';
import {RouteConfig, AsyncRoute, Route} from 'angular2/src/router/route_config_decorator';
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';

import {bind} from 'angular2/di';
Expand Down Expand Up @@ -133,6 +133,21 @@ export function main() {
expect(stringifyInstruction(instruction)).toEqual('first/second');
});

it('should generate an instruction with terminal async routes',
inject([AsyncTestCompleter], (async) => {
var outlet = makeDummyOutlet();

router.registerOutlet(outlet);
router.config([new AsyncRoute({path: '/first', loader: loader, as: 'FirstCmp'})]);

var instruction = router.generate(['/FirstCmp']);
router.navigateInstruction(instruction)
.then((_) => {
expect(outlet.spy('commit')).toHaveBeenCalled();
async.done();
});
}));

describe('query string params', () => {
it('should use query string params for the root route', () => {
router.config(
Expand Down Expand Up @@ -178,6 +193,10 @@ export function main() {
});
}

function loader(): Promise<Type> {
return PromiseWrapper.resolve(DummyComponent);
}

@proxy
@IMPLEMENTS(RouterOutlet)
class DummyOutlet extends SpyObject {
Expand Down
X Tutup