refactor(router): rename navigate and navigateInstruction methods

This commit is contained in:
Brian Ford 2015-09-08 21:41:56 -07:00
parent 5e49d7e624
commit acc2722cb8
17 changed files with 126 additions and 125 deletions

View File

@ -78,7 +78,7 @@ function main() {
"var router = new RootRouter(registry, undefined, location, new Object());",
"$rootScope.$watch(function () { return $location.path(); }, function (path) {",
"if (router.lastNavigationAttempt !== path) {",
"router.navigate(path);",
"router.navigateByUrl(path);",
"}",
"});",

View File

@ -14,7 +14,7 @@
angular.module('myApp', ['ngComponentRouter'])
.controller('MyCtrl', ['$router', function ($router) {
console.log($router);
$router.navigate('/')
$router.navigateByUrl('/')
.then(console.log.bind(console, 'resolve'), console.log.bind(console, 'reject'));
}]);
</script>

View File

@ -307,7 +307,7 @@ function anchorLinkDirective($router) {
var href = element.attr(hrefAttrName);
if (href && $router.recognize(href)) {
$router.navigate(href);
$router.navigateByUrl(href);
event.preventDefault();
}
});

View File

@ -63,7 +63,7 @@ describe('$componentMapper', function () {
{ path: '/', component: Ctrl }
]);
$router.navigate('/');
$router.navigateByUrl('/');
$rootScope.$digest();
expect(elt.text()).toBe('howdy');

View File

@ -51,7 +51,7 @@ describe('ngOutlet', function () {
]);
compile('<div>outer { <div ng-outlet></div> }</div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(spy).toHaveBeenCalled();
@ -69,7 +69,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
expect(spy).toHaveBeenCalledWith(instructionFor(UserController), undefined);
@ -88,9 +88,9 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
$router.navigate('/post/123');
$router.navigateByUrl('/post/123');
$rootScope.$digest();
expect(spy).toHaveBeenCalledWith(instructionFor(activate),
instructionFor(OneController));
@ -108,7 +108,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user');
$router.navigateByUrl('/user');
$rootScope.$digest();
expect(injectedScope).toBeDefined();
@ -127,9 +127,9 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
$router.navigate('/b');
$router.navigateByUrl('/b');
$rootScope.$digest();
expect(spy).toHaveBeenCalled();
});
@ -147,9 +147,9 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
$router.navigate('/post/123');
$router.navigateByUrl('/post/123');
$rootScope.$digest();
expect(spy).toHaveBeenCalledWith(instructionFor(OneController),
instructionFor(deactivate));
@ -177,9 +177,9 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
$router.navigate('/b');
$router.navigateByUrl('/b');
$rootScope.$digest();
expect(log).toEqual(['deactivate', 'activate']);
@ -207,13 +207,13 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/on-reuse/1/a');
$router.navigateByUrl('/on-reuse/1/a');
$rootScope.$digest();
expect(log).toEqual([]);
expect(cmpInstanceCount).toBe(1);
expect(elt.text()).toBe('outer { reuse {one} }');
$router.navigate('/on-reuse/2/b');
$router.navigateByUrl('/on-reuse/2/b');
$rootScope.$digest();
expect(log).toEqual(['reuse: on-reuse/1 -> on-reuse/2']);
expect(cmpInstanceCount).toBe(1);
@ -242,13 +242,13 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/never-reuse/1/a');
$router.navigateByUrl('/never-reuse/1/a');
$rootScope.$digest();
expect(log).toEqual([]);
expect(cmpInstanceCount).toBe(1);
expect(elt.text()).toBe('outer { reuse {one} }');
$router.navigate('/never-reuse/2/b');
$router.navigateByUrl('/never-reuse/2/b');
$rootScope.$digest();
expect(log).toEqual([]);
expect(cmpInstanceCount).toBe(2);
@ -270,7 +270,7 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(spy).not.toHaveBeenCalled();
@ -292,7 +292,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(spy).toHaveBeenCalled();
@ -314,7 +314,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(spy).toHaveBeenCalled();
@ -335,7 +335,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
expect(spy).toHaveBeenCalledWith({name: 'brian'}, $http);
}));
@ -354,11 +354,11 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(elt.text()).toBe('outer { hi }');
$router.navigate('/b');
$router.navigateByUrl('/b');
$rootScope.$digest();
expect(elt.text()).toBe('outer { hi }');
});
@ -377,11 +377,11 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(elt.text()).toBe('outer { hi }');
$router.navigate('/b');
$router.navigateByUrl('/b');
$rootScope.$digest();
expect(elt.text()).toBe('outer { one }');
});
@ -401,7 +401,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(spy).toHaveBeenCalled();
@ -421,9 +421,9 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
$router.navigate('/post/123');
$router.navigateByUrl('/post/123');
$rootScope.$digest();
expect(spy).toHaveBeenCalledWith(instructionFor(OneController),
instructionFor(deactivate));

View File

@ -43,7 +43,7 @@ describe('navigation', function () {
{ path: '/', component: OneController }
]);
$router.navigate('/');
$router.navigateByUrl('/');
$rootScope.$digest();
expect(elt.text()).toBe('one');
@ -59,7 +59,7 @@ describe('navigation', function () {
spyOn(console, 'warn');
compile('<ng-outlet></ng-outlet>');
$router.navigate('/');
$router.navigateByUrl('/');
expect(console.warn).toHaveBeenCalledWith('Could not find controller for', 'NoControllerController');
expect(elt.text()).toBe('4');
@ -72,11 +72,11 @@ describe('navigation', function () {
]);
compile('<ng-outlet></ng-outlet>');
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
expect(elt.text()).toBe('hello brian');
$router.navigate('/user/igor');
$router.navigateByUrl('/user/igor');
$rootScope.$digest();
expect(elt.text()).toBe('hello igor');
});
@ -97,14 +97,14 @@ describe('navigation', function () {
]);
compile('<ng-outlet></ng-outlet>');
$router.navigate('/parent/user/brian');
$router.navigateByUrl('/parent/user/brian');
$rootScope.$digest();
expect(spy).toHaveBeenCalled();
expect(elt.text()).toBe('parent { hello brian }');
spy.calls.reset();
$router.navigate('/parent/user/igor');
$router.navigateByUrl('/parent/user/igor');
$rootScope.$digest();
expect(spy).not.toHaveBeenCalled();
expect(elt.text()).toBe('parent { hello igor }');
@ -121,7 +121,7 @@ describe('navigation', function () {
]);
compile('<div>outer { <div ng-outlet></div> }</div>');
$router.navigate('/a/b');
$router.navigateByUrl('/a/b');
$rootScope.$digest();
expect(elt.text()).toBe('outer { inner { one } }');
@ -136,7 +136,7 @@ describe('navigation', function () {
]);
compile('<div>root { <div ng-outlet></div> }</div>');
$router.navigate('/');
$router.navigateByUrl('/');
$rootScope.$digest();
expect(elt.text()).toBe('root { one }');
});
@ -152,7 +152,7 @@ describe('navigation', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/user');
$router.navigateByUrl('/user');
$rootScope.$digest();
expect(injectedScope).toBeDefined();
@ -166,7 +166,7 @@ describe('navigation', function () {
compile('<div ng-outlet></div>');
$router.navigate('/user');
$router.navigateByUrl('/user');
$rootScope.$digest();
expect($location.path()).toBe('/user');
@ -181,7 +181,7 @@ describe('navigation', function () {
{ path: '/user', component: UserController }
]);
$router.navigate('/');
$router.navigateByUrl('/');
$rootScope.$digest();
expect($location.path()).toBe('/user');
@ -203,13 +203,13 @@ describe('navigation', function () {
compile('<div ng-outlet></div>');
$router.navigate('/old-parent/old-child');
$router.navigateByUrl('/old-parent/old-child');
$rootScope.$digest();
expect($location.path()).toBe('/new-parent/new-child');
expect(elt.text()).toBe('inner { one }');
$router.navigate('/old-parent/old-child-two');
$router.navigateByUrl('/old-parent/old-child-two');
$rootScope.$digest();
expect($location.path()).toBe('/new-parent/new-child-two');
@ -243,7 +243,7 @@ describe('navigation', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/pendingActivate');
$router.navigateByUrl('/pendingActivate');
$rootScope.$digest();
expect($router.navigating).toBe(true);
defer.resolve();

View File

@ -42,7 +42,7 @@ describe('ngOutlet', function () {
]);
compile('<a ng-link="[\'/two\']">link</a> | outer { <div ng-outlet></div> }');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(elt.find('a').attr('href')).toBe('./b');
@ -57,7 +57,7 @@ describe('ngOutlet', function () {
]);
compile('outer { <div ng-outlet></div> }');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(elt.find('a').attr('href')).toBe('./b');
@ -74,7 +74,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(elt.find('a').attr('href')).toBe('./b/lol');
@ -91,7 +91,7 @@ describe('ngOutlet', function () {
]);
compile('<div ng-outlet></div>');
$router.navigate('/a');
$router.navigateByUrl('/a');
$rootScope.$digest();
expect(elt.find('a').attr('href')).toBe('./b/one');

View File

@ -46,7 +46,7 @@ describe('ngOutlet animations', function () {
{ path: '/user/:name', component: UserController }
]);
$router.navigate('/user/brian');
$router.navigateByUrl('/user/brian');
$rootScope.$digest();
expect(elt.text()).toBe('hello brian');
@ -55,7 +55,7 @@ describe('ngOutlet animations', function () {
expect(item.event).toBe('enter');
// navigate to pete
$router.navigate('/user/pete');
$router.navigateByUrl('/user/pete');
$rootScope.$digest();
expect(elt.text()).toBe('hello pete');

View File

@ -159,7 +159,7 @@ export class Router {
* If the given URL begins with a `/`, router will navigate absolutely.
* If the given URL does not begin with `/`, the router will navigate relative to this component.
*/
navigate(url: string, _skipLocationChange: boolean = false): Promise<any> {
navigateByUrl(url: string, _skipLocationChange: boolean = false): Promise<any> {
return this._currentNavigation = this._currentNavigation.then((_) => {
this.lastNavigationAttempt = url;
this._startNavigating();
@ -177,8 +177,8 @@ export class Router {
* Navigate via the provided instruction. Returns a promise that resolves when navigation is
* complete.
*/
navigateInstruction(instruction: Instruction,
_skipLocationChange: boolean = false): Promise<any> {
navigateByInstruction(instruction: Instruction,
_skipLocationChange: boolean = false): Promise<any> {
if (isBlank(instruction)) {
return _resolveToFalse;
}
@ -373,7 +373,7 @@ export class Router {
if (isBlank(this.lastNavigationAttempt)) {
return this._currentNavigation;
}
return this.navigate(this.lastNavigationAttempt);
return this.navigateByUrl(this.lastNavigationAttempt);
}
@ -445,10 +445,11 @@ export class RootRouter extends Router {
hostComponent: Type) {
super(registry, pipeline, null, hostComponent);
this._location = location;
this._location.subscribe((change) => this.navigate(change['url'], isPresent(change['pop'])));
this._location.subscribe((change) =>
this.navigateByUrl(change['url'], isPresent(change['pop'])));
this.registry.configFromComponent(hostComponent);
this.navigate(location.path());
this.navigateByUrl(location.path());
}
commit(instruction: Instruction, _skipLocationChange: boolean = false): Promise<any> {
@ -471,15 +472,15 @@ class ChildRouter extends Router {
}
navigate(url: string, _skipLocationChange: boolean = false): Promise<any> {
navigateByUrl(url: string, _skipLocationChange: boolean = false): Promise<any> {
// Delegate navigation to the root router
return this.parent.navigate(url, _skipLocationChange);
return this.parent.navigateByUrl(url, _skipLocationChange);
}
navigateInstruction(instruction: Instruction,
_skipLocationChange: boolean = false): Promise<any> {
navigateByInstruction(instruction: Instruction,
_skipLocationChange: boolean = false): Promise<any> {
// Delegate navigation to the root router
return this.parent.navigateInstruction(instruction, _skipLocationChange);
return this.parent.navigateByInstruction(instruction, _skipLocationChange);
}
}

View File

@ -66,7 +66,7 @@ export class RouterLink {
}
onClick(): boolean {
this._router.navigateInstruction(this._navigationInstruction);
this._router.navigateByInstruction(this._navigationInstruction);
return false;
}
}

View File

@ -91,7 +91,7 @@ export function main() {
it('should call the onActivate hook', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/on-activate'))
.then((_) => rtr.navigateByUrl('/on-activate'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('activate cmp');
@ -110,7 +110,7 @@ export function main() {
completer.resolve(true);
}
});
rtr.navigate('/parent-activate/child-activate')
rtr.navigateByUrl('/parent-activate/child-activate')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('parent {activate cmp}');
@ -126,8 +126,8 @@ export function main() {
it('should call the onDeactivate hook', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/on-deactivate'))
.then((_) => rtr.navigate('/a'))
.then((_) => rtr.navigateByUrl('/on-deactivate'))
.then((_) => rtr.navigateByUrl('/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A');
@ -140,7 +140,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/parent-deactivate/child-deactivate'))
.then((_) => rtr.navigateByUrl('/parent-deactivate/child-deactivate'))
.then((_) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('deactivate')) {
@ -149,7 +149,7 @@ export function main() {
expect(rootTC.nativeElement).toHaveText('parent {deactivate cmp}');
}
});
rtr.navigate('/a').then((_) => {
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A');
expect(log).toEqual([
@ -165,14 +165,14 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/on-reuse/1/a'))
.then((_) => rtr.navigateByUrl('/on-reuse/1/a'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1);
})
.then((_) => rtr.navigate('/on-reuse/2/b'))
.then((_) => rtr.navigateByUrl('/on-reuse/2/b'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual(['reuse: /on-reuse/1 -> /on-reuse/2']);
@ -187,14 +187,14 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/never-reuse/1/a'))
.then((_) => rtr.navigateByUrl('/never-reuse/1/a'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual([]);
expect(rootTC.nativeElement).toHaveText('reuse {A}');
expect(cmpInstanceCount).toBe(1);
})
.then((_) => rtr.navigate('/never-reuse/2/b'))
.then((_) => rtr.navigateByUrl('/never-reuse/2/b'))
.then((_) => {
rootTC.detectChanges();
expect(log).toEqual([]);
@ -214,7 +214,7 @@ export function main() {
completer.resolve(true);
}
});
rtr.navigate('/can-activate/a')
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canActivate {A}');
@ -234,7 +234,7 @@ export function main() {
completer.resolve(false);
}
});
rtr.navigate('/can-activate/a')
rtr.navigateByUrl('/can-activate/a')
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('');
@ -248,7 +248,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/can-deactivate/a'))
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
@ -260,7 +260,7 @@ export function main() {
}
});
rtr.navigate('/a').then((_) => {
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('A');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
@ -273,7 +273,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/can-deactivate/a'))
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
@ -285,7 +285,7 @@ export function main() {
}
});
rtr.navigate('/a').then((_) => {
rtr.navigateByUrl('/a').then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
@ -299,7 +299,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/activation-hooks/child'))
.then((_) => rtr.navigateByUrl('/activation-hooks/child'))
.then((_) => {
expect(log).toEqual([
'canActivate child: null -> /child',
@ -309,7 +309,7 @@ export function main() {
]);
log = [];
return rtr.navigate('/a');
return rtr.navigateByUrl('/a');
})
.then((_) => {
expect(log).toEqual([
@ -325,7 +325,7 @@ export function main() {
it('should only run reuse hooks when reusing', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/reuse-hooks/1'))
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
.then((_) => {
expect(log).toEqual(
['canActivate: null -> /reuse-hooks/1', 'onActivate: null -> /reuse-hooks/1']);
@ -338,7 +338,7 @@ export function main() {
log = [];
return rtr.navigate('/reuse-hooks/2');
return rtr.navigateByUrl('/reuse-hooks/2');
})
.then((_) => {
expect(log).toEqual([
@ -352,7 +352,7 @@ export function main() {
it('should not run reuse hooks when not reusing', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/reuse-hooks/1'))
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
.then((_) => {
expect(log).toEqual(
['canActivate: null -> /reuse-hooks/1', 'onActivate: null -> /reuse-hooks/1']);
@ -364,7 +364,7 @@ export function main() {
});
log = [];
return rtr.navigate('/reuse-hooks/2');
return rtr.navigateByUrl('/reuse-hooks/2');
})
.then((_) => {
expect(log).toEqual([

View File

@ -75,7 +75,7 @@ export function main() {
it('should work in a simple case', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/test', component: HelloCmp})]))
.then((_) => rtr.navigate('/test'))
.then((_) => rtr.navigateByUrl('/test'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello');
@ -88,12 +88,12 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/user/:name', component: UserCmp})]))
.then((_) => rtr.navigate('/user/brian'))
.then((_) => rtr.navigateByUrl('/user/brian'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello brian');
})
.then((_) => rtr.navigate('/user/igor'))
.then((_) => rtr.navigateByUrl('/user/igor'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello igor');
@ -105,7 +105,7 @@ export function main() {
it('should navigate to child routes', inject([AsyncTestCompleter], (async) => {
compile('outer { <router-outlet></router-outlet> }')
.then((_) => rtr.config([new Route({path: '/a/...', component: ParentCmp})]))
.then((_) => rtr.navigate('/a/b'))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('outer { inner { hello } }');
@ -117,7 +117,7 @@ export function main() {
it('should navigate to child routes of async routes', inject([AsyncTestCompleter], (async) => {
compile('outer { <router-outlet></router-outlet> }')
.then((_) => rtr.config([new AsyncRoute({path: '/a/...', loader: parentLoader})]))
.then((_) => rtr.navigate('/a/b'))
.then((_) => rtr.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('outer { inner { hello } }');
@ -133,7 +133,7 @@ export function main() {
new Redirect({path: '/original', redirectTo: '/redirected'}),
new Route({path: '/redirected', component: HelloCmp})
]))
.then((_) => rtr.navigate('/original'))
.then((_) => rtr.navigateByUrl('/original'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('hello');
@ -146,13 +146,13 @@ export function main() {
it('should reuse common parent components', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/team/:id/...', component: TeamCmp})]))
.then((_) => rtr.navigate('/team/angular/user/rado'))
.then((_) => rtr.navigateByUrl('/team/angular/user/rado'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello rado }');
})
.then((_) => rtr.navigate('/team/angular/user/victor'))
.then((_) => rtr.navigateByUrl('/team/angular/user/victor'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1);
@ -165,14 +165,14 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/team/:id/...', component: TeamCmp})]))
.then((_) => rtr.navigate('/team/angular/user/rado'))
.then((_) => rtr.navigateByUrl('/team/angular/user/rado'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(1);
expect(childCmpInstanceCount).toBe(1);
expect(rootTC.nativeElement).toHaveText('team angular { hello rado }');
})
.then((_) => rtr.navigate('/team/dart/user/rado'))
.then((_) => rtr.navigateByUrl('/team/dart/user/rado'))
.then((_) => {
rootTC.detectChanges();
expect(cmpInstanceCount).toBe(2);
@ -187,7 +187,7 @@ export function main() {
.then((_) => rtr.config([
new Route({path: '/route-data', component: RouteDataCmp, data: {'isAdmin': true}})
]))
.then((_) => rtr.navigate('/route-data'))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify({'isAdmin': true}));
@ -202,7 +202,7 @@ export function main() {
new AsyncRoute(
{path: '/route-data', loader: AsyncRouteDataCmp, data: {isAdmin: true}})
]))
.then((_) => rtr.navigate('/route-data'))
.then((_) => rtr.navigateByUrl('/route-data'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify({'isAdmin': true}));
@ -215,7 +215,7 @@ export function main() {
compile()
.then((_) => rtr.config(
[new Route({path: '/route-data-default', component: RouteDataCmp})]))
.then((_) => rtr.navigate('/route-data-default'))
.then((_) => rtr.navigateByUrl('/route-data-default'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('null');
@ -228,7 +228,7 @@ export function main() {
.then((_) => rtr.config([
new Route({path: '/route-data-array', component: RouteDataCmp, data: [1, 2, 3]})
]))
.then((_) => rtr.navigate('/route-data-array'))
.then((_) => rtr.navigateByUrl('/route-data-array'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify([1, 2, 3]));
@ -242,7 +242,7 @@ export function main() {
new Route(
{path: '/route-data-string', component: RouteDataCmp, data: 'hello world'})
]))
.then((_) => rtr.navigate('/route-data-string'))
.then((_) => rtr.navigateByUrl('/route-data-string'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText(Json.stringify('hello world'));
@ -254,7 +254,7 @@ export function main() {
it('should recognize a simple case', inject([AsyncTestCompleter], (async) => {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: AuxCmp})]))
.then((_) => rtr.navigate('/hello(modal)'))
.then((_) => rtr.navigateByUrl('/hello(modal)'))
.then((_) => {
rootTC.detectChanges();
expect(rootTC.nativeElement).toHaveText('main {hello} | aux {modal}');

View File

@ -72,7 +72,7 @@ export function main() {
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
tcb.createAsync(AppCmp).then((rootTC) => {
var router = rootTC.componentInstance.router;
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => {
expect(rootTC.nativeElement).toHaveText('outer { oh no }');
expect(error).toContainError('oops!');
async.done();
@ -123,11 +123,11 @@ export function main() {
if (flipped) {
location.back();
} else {
router.navigate(nextUrl);
router.navigateByUrl(nextUrl);
}
});
router.navigate(history[0][0]);
router.navigateByUrl(history[0][0]);
});
}), 1000);
});
@ -146,7 +146,7 @@ export function main() {
expect(rootTC.componentInstance.location.path()).toEqual('/parent/child');
async.done();
});
router.navigate('/parent/child');
router.navigateByUrl('/parent/child');
});
}), 1000);
@ -165,7 +165,7 @@ export function main() {
.toEqual('/my/app/parent/child');
async.done();
});
router.navigate('/parent/child');
router.navigateByUrl('/parent/child');
});
}),
1000);
@ -190,7 +190,7 @@ export function main() {
.toEqual('/qs?q=search-for-something');*/
async.done();
});
router.navigate('/qs?q=search-for-something');
router.navigateByUrl('/qs?q=search-for-something');
rootTC.detectChanges();
});
}), 1000);

View File

@ -76,7 +76,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) =>
router.config([new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(getHref(rootTC)).toEqual('/my/base/user');
@ -89,7 +89,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) =>
router.config([new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
expect(getHref(rootTC)).toEqual('/user');
@ -102,7 +102,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\', {name: name}]">{{name}}</a>')
.then((_) => router.config(
[new Route({path: '/user/:name', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.componentInstance.name = 'brian';
rootTC.detectChanges();
@ -118,7 +118,7 @@ export function main() {
compile()
.then((_) => router.config(
[new Route({path: '/page/:number', component: SiblingPageCmp, as: 'page'})]))
.then((_) => router.navigate('/page/1'))
.then((_) => router.navigateByUrl('/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(
@ -159,7 +159,7 @@ export function main() {
compile()
.then((_) => router.config(
[new Route({path: '/book/:title/...', component: BookCmp, as: 'book'})]))
.then((_) => router.navigate('/book/1984/page/1'))
.then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => {
rootTC.detectChanges();
expect(DOM.getAttribute(
@ -206,7 +206,7 @@ export function main() {
async.done();
});
router.navigate('/better-child');
router.navigateByUrl('/better-child');
});
}));
@ -247,7 +247,7 @@ export function main() {
async.done();
});
router.navigate('/child-with-grandchild/grandchild');
router.navigateByUrl('/child-with-grandchild/grandchild');
});
}));
});
@ -265,7 +265,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();
@ -286,7 +286,7 @@ export function main() {
compile('<a href="hello" [router-link]="[\'./user\']"></a>')
.then((_) => router.config(
[new Route({path: '/user', component: UserCmp, as: 'user'})]))
.then((_) => router.navigate('/a/b'))
.then((_) => router.navigateByUrl('/a/b'))
.then((_) => {
rootTC.detectChanges();

View File

@ -64,7 +64,7 @@ export function main() {
expect(applicationRef.hostComponent.location.path()).toEqual('/parent/child');
async.done();
});
router.navigate('/parent/child');
router.navigateByUrl('/parent/child');
});
}), 1000);
@ -78,7 +78,7 @@ export function main() {
expect(applicationRef.hostComponent.location.path()).toEqual('/after');
async.done();
});
router.navigate('/before');
router.navigateByUrl('/before');
});
}), 1000);
@ -92,7 +92,7 @@ export function main() {
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigate('/hello');
router.navigateByUrl('/hello');
});
}), 1000);
@ -107,7 +107,7 @@ export function main() {
expect(applicationRef.hostComponent.location.path()).toEqual('/hello');
async.done();
});
router.navigate('/hello');
router.navigateByUrl('/hello');
});
}), 1000);

View File

@ -66,7 +66,7 @@ export function main() {
testComponent.detectChanges();
// TODO: shouldn't this be just 'click' rather than '^click'?
testComponent.query(By.css('a')).triggerEventHandler('click', null);
expect(router.spy('navigateInstruction')).toHaveBeenCalledWith(dummyInstruction);
expect(router.spy('navigateByInstruction')).toHaveBeenCalledWith(dummyInstruction);
async.done();
});
}));

View File

@ -68,7 +68,7 @@ export function main() {
router.registerPrimaryOutlet(outlet)
.then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
.then((_) => router.navigate('/a'))
.then((_) => router.navigateByUrl('/a'))
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();
expect(location.urlChanges).toEqual(['/a']);
@ -82,7 +82,7 @@ export function main() {
router.registerPrimaryOutlet(outlet)
.then((_) => router.config([new Route({path: '/b', component: DummyComponent})]))
.then((_) => router.navigate('/b', true))
.then((_) => router.navigateByUrl('/b', true))
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();
expect(location.urlChanges).toEqual([]);
@ -95,7 +95,7 @@ export function main() {
var outlet = makeDummyOutlet();
router.registerPrimaryOutlet(outlet)
.then((_) => router.navigate('/a'))
.then((_) => router.navigateByUrl('/a'))
.then((_) => {
expect(outlet.spy('activate')).not.toHaveBeenCalled();
return router.config([new Route({path: '/a', component: DummyComponent})]);
@ -146,7 +146,7 @@ export function main() {
router.config([new AsyncRoute({path: '/first', loader: loader, as: 'FirstCmp'})]);
var instruction = router.generate(['/FirstCmp']);
router.navigateInstruction(instruction)
router.navigateByInstruction(instruction)
.then((_) => {
expect(outlet.spy('activate')).toHaveBeenCalled();
async.done();
@ -162,7 +162,7 @@ export function main() {
new Route({path: '/a', component: DummyComponent, as: 'A'}),
new Route({path: '/b', component: DummyComponent, as: 'B'})
]))
.then((_) => router.navigate('/a'))
.then((_) => router.navigateByUrl('/a'))
.then((_) => {
var instruction = router.generate(['/A']);
var otherInstruction = router.generate(['/B']);