refactor(router): use CamelCase aliases for routes

This commit is contained in:
Brian Ford 2015-09-14 17:36:32 -07:00
parent 97d1844bfc
commit cb4a9a3c04
11 changed files with 98 additions and 98 deletions

View File

@ -38,9 +38,9 @@ describe('ngOutlet', function () {
$router.config([ $router.config([
{ path: '/a', component: OneController }, { path: '/a', component: OneController },
{ path: '/b', component: TwoController, as: 'two' } { path: '/b', component: TwoController, as: 'Two' }
]); ]);
compile('<a ng-link="[\'/two\']">link</a> | outer { <div ng-outlet></div> }'); compile('<a ng-link="[\'/Two\']">link</a> | outer { <div ng-outlet></div> }');
$router.navigateByUrl('/a'); $router.navigateByUrl('/a');
$rootScope.$digest(); $rootScope.$digest();
@ -49,11 +49,11 @@ describe('ngOutlet', function () {
}); });
it('should allow linking from the child and the parent', function () { it('should allow linking from the child and the parent', function () {
put('one', '<div><a ng-link="[\'/two\']">{{number}}</a></div>'); put('one', '<div><a ng-link="[\'/Two\']">{{number}}</a></div>');
$router.config([ $router.config([
{ path: '/a', component: OneController }, { path: '/a', component: OneController },
{ path: '/b', component: TwoController, as: 'two' } { path: '/b', component: TwoController, as: 'Two' }
]); ]);
compile('outer { <div ng-outlet></div> }'); compile('outer { <div ng-outlet></div> }');
@ -66,11 +66,11 @@ describe('ngOutlet', function () {
it('should allow params in routerLink directive', function () { it('should allow params in routerLink directive', function () {
put('router', '<div>outer { <div ng-outlet></div> }</div>'); put('router', '<div>outer { <div ng-outlet></div> }</div>');
put('one', '<div><a ng-link="[\'/two\', {param: \'lol\'}]">{{number}}</a></div>'); put('one', '<div><a ng-link="[\'/Two\', {param: \'lol\'}]">{{number}}</a></div>');
$router.config([ $router.config([
{ path: '/a', component: OneController }, { path: '/a', component: OneController },
{ path: '/b/:param', component: TwoController, as: 'two' } { path: '/b/:param', component: TwoController, as: 'Two' }
]); ]);
compile('<div ng-outlet></div>'); compile('<div ng-outlet></div>');
@ -83,11 +83,11 @@ describe('ngOutlet', function () {
// TODO: test dynamic links // TODO: test dynamic links
it('should update the href of links with bound params', function () { it('should update the href of links with bound params', function () {
put('router', '<div>outer { <div ng-outlet></div> }</div>'); put('router', '<div>outer { <div ng-outlet></div> }</div>');
put('one', '<div><a ng-link="[\'/two\', {param: one.number}]">{{one.number}}</a></div>'); put('one', '<div><a ng-link="[\'/Two\', {param: one.number}]">{{one.number}}</a></div>');
$router.config([ $router.config([
{ path: '/a', component: OneController }, { path: '/a', component: OneController },
{ path: '/b/:param', component: TwoController, as: 'two' } { path: '/b/:param', component: TwoController, as: 'Two' }
]); ]);
compile('<div ng-outlet></div>'); compile('<div ng-outlet></div>');

View File

@ -72,9 +72,9 @@ export function main() {
it('should generate absolute hrefs that include the base href', it('should generate absolute hrefs that include the base href',
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
location.setBaseHref('/my/base'); location.setBaseHref('/my/base');
compile('<a href="hello" [router-link]="[\'./user\']"></a>') compile('<a href="hello" [router-link]="[\'./User\']"></a>')
.then((_) => .then((_) =>
router.config([new Route({path: '/user', component: UserCmp, as: 'user'})])) router.config([new Route({path: '/user', component: UserCmp, as: 'User'})]))
.then((_) => router.navigateByUrl('/a/b')) .then((_) => router.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
@ -85,9 +85,9 @@ export function main() {
it('should generate link hrefs without params', inject([AsyncTestCompleter], (async) => { it('should generate link hrefs without params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [router-link]="[\'./user\']"></a>') compile('<a href="hello" [router-link]="[\'./User\']"></a>')
.then((_) => .then((_) =>
router.config([new Route({path: '/user', component: UserCmp, as: 'user'})])) router.config([new Route({path: '/user', component: UserCmp, as: 'User'})]))
.then((_) => router.navigateByUrl('/a/b')) .then((_) => router.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
@ -98,9 +98,9 @@ export function main() {
it('should generate link hrefs with params', inject([AsyncTestCompleter], (async) => { it('should generate link hrefs with params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [router-link]="[\'./user\', {name: name}]">{{name}}</a>') compile('<a href="hello" [router-link]="[\'./User\', {name: name}]">{{name}}</a>')
.then((_) => router.config( .then((_) => router.config(
[new Route({path: '/user/:name', component: UserCmp, as: 'user'})])) [new Route({path: '/user/:name', component: UserCmp, as: 'User'})]))
.then((_) => router.navigateByUrl('/a/b')) .then((_) => router.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.debugElement.componentInstance.name = 'brian'; rootTC.debugElement.componentInstance.name = 'brian';
@ -117,7 +117,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
compile() compile()
.then((_) => router.config( .then((_) => router.config(
[new Route({path: '/page/:number', component: SiblingPageCmp, as: 'page'})])) [new Route({path: '/page/:number', component: SiblingPageCmp, as: 'Page'})]))
.then((_) => router.navigateByUrl('/page/1')) .then((_) => router.navigateByUrl('/page/1'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
@ -137,10 +137,10 @@ export function main() {
new AsyncRoute({ new AsyncRoute({
path: '/child-with-grandchild/...', path: '/child-with-grandchild/...',
loader: parentCmpLoader, loader: parentCmpLoader,
as: 'child-with-grandchild' as: 'ChildWithGrandchild'
}) })
])) ]))
.then((_) => router.navigate(['/child-with-grandchild'])) .then((_) => router.navigate(['/ChildWithGrandchild']))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1] expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[1]
@ -156,7 +156,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
compile() compile()
.then((_) => router.config( .then((_) => router.config(
[new Route({path: '/book/:title/...', component: BookCmp, as: 'book'})])) [new Route({path: '/book/:title/...', component: BookCmp, as: 'Book'})]))
.then((_) => router.navigateByUrl('/book/1984/page/1')) .then((_) => router.navigateByUrl('/book/1984/page/1'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
@ -180,11 +180,11 @@ export function main() {
describe('router-link-active CSS class', () => { describe('router-link-active CSS class', () => {
it('should be added to the associated element', inject([AsyncTestCompleter], (async) => { it('should be added to the associated element', inject([AsyncTestCompleter], (async) => {
router.config([ router.config([
new Route({path: '/child', component: HelloCmp, as: 'child'}), new Route({path: '/child', component: HelloCmp, as: 'Child'}),
new Route({path: '/better-child', component: Hello2Cmp, as: 'better-child'}) new Route({path: '/better-child', component: Hello2Cmp, as: 'BetterChild'})
]) ])
.then((_) => compile(`<a [router-link]="['./child']" class="child-link">Child</a> .then((_) => compile(`<a [router-link]="['./Child']" class="child-link">Child</a>
<a [router-link]="['./better-child']" class="better-child-link">Better Child</a> <a [router-link]="['./BetterChild']" class="better-child-link">Better Child</a>
<router-outlet></router-outlet>`)) <router-outlet></router-outlet>`))
.then((_) => { .then((_) => {
var element = rootTC.debugElement.nativeElement; var element = rootTC.debugElement.nativeElement;
@ -211,15 +211,15 @@ export function main() {
it('should be added to links in child routes', inject([AsyncTestCompleter], (async) => { it('should be added to links in child routes', inject([AsyncTestCompleter], (async) => {
router.config([ router.config([
new Route({path: '/child', component: HelloCmp, as: 'child'}), new Route({path: '/child', component: HelloCmp, as: 'Child'}),
new Route({ new Route({
path: '/child-with-grandchild/...', path: '/child-with-grandchild/...',
component: ParentCmp, component: ParentCmp,
as: 'child-with-grandchild' as: 'ChildWithGrandchild'
}) })
]) ])
.then((_) => compile(`<a [router-link]="['./child']" class="child-link">Child</a> .then((_) => compile(`<a [router-link]="['./Child']" class="child-link">Child</a>
<a [router-link]="['./child-with-grandchild/grandchild']" class="child-with-grandchild-link">Better Child</a> <a [router-link]="['./ChildWithGrandchild/Grandchild']" class="child-with-grandchild-link">Better Child</a>
<router-outlet></router-outlet>`)) <router-outlet></router-outlet>`))
.then((_) => { .then((_) => {
var element = rootTC.debugElement.nativeElement; var element = rootTC.debugElement.nativeElement;
@ -261,9 +261,9 @@ export function main() {
}; };
it('should navigate to link hrefs without params', inject([AsyncTestCompleter], (async) => { it('should navigate to link hrefs without params', inject([AsyncTestCompleter], (async) => {
compile('<a href="hello" [router-link]="[\'./user\']"></a>') compile('<a href="hello" [router-link]="[\'./User\']"></a>')
.then((_) => router.config( .then((_) => router.config(
[new Route({path: '/user', component: UserCmp, as: 'user'})])) [new Route({path: '/user', component: UserCmp, as: 'User'})]))
.then((_) => router.navigateByUrl('/a/b')) .then((_) => router.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
@ -282,9 +282,9 @@ export function main() {
it('should navigate to link hrefs in presence of base href', it('should navigate to link hrefs in presence of base href',
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
location.setBaseHref('/base'); location.setBaseHref('/base');
compile('<a href="hello" [router-link]="[\'./user\']"></a>') compile('<a href="hello" [router-link]="[\'./User\']"></a>')
.then((_) => router.config( .then((_) => router.config(
[new Route({path: '/user', component: UserCmp, as: 'user'})])) [new Route({path: '/user', component: UserCmp, as: 'User'})]))
.then((_) => router.navigateByUrl('/a/b')) .then((_) => router.navigateByUrl('/a/b'))
.then((_) => { .then((_) => {
rootTC.detectChanges(); rootTC.detectChanges();
@ -322,7 +322,7 @@ class UserCmp {
@Component({selector: 'page-cmp'}) @Component({selector: 'page-cmp'})
@View({ @View({
template: template:
`page #{{pageNumber}} | <a href="hello" [router-link]="[\'../page\', {number: nextPage}]">next</a>`, `page #{{pageNumber}} | <a href="hello" [router-link]="[\'../Page\', {number: nextPage}]">next</a>`,
directives: [RouterLink] directives: [RouterLink]
}) })
class SiblingPageCmp { class SiblingPageCmp {
@ -350,14 +350,14 @@ function parentCmpLoader() {
@Component({selector: 'parent-cmp'}) @Component({selector: 'parent-cmp'})
@View({ @View({
template: `{ <a [router-link]="['./grandchild']" class="grandchild-link">Grandchild</a> template: `{ <a [router-link]="['./Grandchild']" class="grandchild-link">Grandchild</a>
<a [router-link]="['./better-grandchild']" class="better-grandchild-link">Better Grandchild</a> <a [router-link]="['./BetterGrandchild']" class="better-grandchild-link">Better Grandchild</a>
<router-outlet></router-outlet> }`, <router-outlet></router-outlet> }`,
directives: ROUTER_DIRECTIVES directives: ROUTER_DIRECTIVES
}) })
@RouteConfig([ @RouteConfig([
new Route({path: '/grandchild', component: HelloCmp, as: 'grandchild'}), new Route({path: '/grandchild', component: HelloCmp, as: 'Grandchild'}),
new Route({path: '/better-grandchild', component: Hello2Cmp, as: 'better-grandchild'}) new Route({path: '/better-grandchild', component: Hello2Cmp, as: 'BetterGrandchild'})
]) ])
class ParentCmp { class ParentCmp {
constructor(public router: Router) {} constructor(public router: Router) {}
@ -365,11 +365,11 @@ class ParentCmp {
@Component({selector: 'book-cmp'}) @Component({selector: 'book-cmp'})
@View({ @View({
template: `<a href="hello" [router-link]="[\'./page\', {number: 100}]">{{title}}</a> | template: `<a href="hello" [router-link]="[\'./Page\', {number: 100}]">{{title}}</a> |
<router-outlet></router-outlet>`, <router-outlet></router-outlet>`,
directives: ROUTER_DIRECTIVES directives: ROUTER_DIRECTIVES
}) })
@RouteConfig([new Route({path: '/page/:number', component: SiblingPageCmp, as: 'page'})]) @RouteConfig([new Route({path: '/page/:number', component: SiblingPageCmp, as: 'Page'})])
class BookCmp { class BookCmp {
title: string; title: string;
constructor(params: RouteParams) { this.title = params.get('title'); } constructor(params: RouteParams) { this.title = params.get('title'); }

View File

@ -108,28 +108,28 @@ export function main() {
it('should generate URLs with params', () => { it('should generate URLs with params', () => {
recognizer.config(new Route({path: '/app/user/:name', component: DummyCmpA, as: 'user'})); recognizer.config(new Route({path: '/app/user/:name', component: DummyCmpA, as: 'User'}));
var instruction = recognizer.generate('user', {'name': 'misko'}); var instruction = recognizer.generate('User', {'name': 'misko'});
expect(instruction.urlPath).toEqual('app/user/misko'); expect(instruction.urlPath).toEqual('app/user/misko');
}); });
it('should generate URLs with numeric params', () => { it('should generate URLs with numeric params', () => {
recognizer.config(new Route({path: '/app/page/:number', component: DummyCmpA, as: 'page'})); recognizer.config(new Route({path: '/app/page/:number', component: DummyCmpA, as: 'Page'}));
expect(recognizer.generate('page', {'number': 42}).urlPath).toEqual('app/page/42'); expect(recognizer.generate('Page', {'number': 42}).urlPath).toEqual('app/page/42');
}); });
it('should throw in the absence of required params URLs', () => { it('should throw in the absence of required params URLs', () => {
recognizer.config(new Route({path: 'app/user/:name', component: DummyCmpA, as: 'user'})); recognizer.config(new Route({path: 'app/user/:name', component: DummyCmpA, as: 'User'}));
expect(() => recognizer.generate('user', {})) expect(() => recognizer.generate('User', {}))
.toThrowError('Route generator for \'name\' was not included in parameters passed.'); .toThrowError('Route generator for \'name\' was not included in parameters passed.');
}); });
describe('params', () => { describe('params', () => {
it('should recognize parameters within the URL path', () => { it('should recognize parameters within the URL path', () => {
recognizer.config(new Route({path: 'profile/:name', component: DummyCmpA, as: 'user'})); recognizer.config(new Route({path: 'profile/:name', component: DummyCmpA, as: 'User'}));
var solution = recognize(recognizer, '/profile/matsko?comments=all'); var solution = recognize(recognizer, '/profile/matsko?comments=all');
expect(solution.params).toEqual({'name': 'matsko', 'comments': 'all'}); expect(solution.params).toEqual({'name': 'matsko', 'comments': 'all'});
}); });
@ -138,18 +138,18 @@ export function main() {
it('should generate and populate the given static-based route with querystring params', it('should generate and populate the given static-based route with querystring params',
() => { () => {
recognizer.config( recognizer.config(
new Route({path: 'forum/featured', component: DummyCmpA, as: 'forum-page'})); new Route({path: 'forum/featured', component: DummyCmpA, as: 'ForumPage'}));
var params = {'start': 10, 'end': 100}; var params = {'start': 10, 'end': 100};
var result = recognizer.generate('forum-page', params); var result = recognizer.generate('ForumPage', params);
expect(result.urlPath).toEqual('forum/featured'); expect(result.urlPath).toEqual('forum/featured');
expect(result.urlParams).toEqual(['start=10', 'end=100']); expect(result.urlParams).toEqual(['start=10', 'end=100']);
}); });
it('should prefer positional params over query params', () => { it('should prefer positional params over query params', () => {
recognizer.config(new Route({path: 'profile/:name', component: DummyCmpA, as: 'user'})); recognizer.config(new Route({path: 'profile/:name', component: DummyCmpA, as: 'User'}));
var solution = recognize(recognizer, '/profile/yegor?name=igor'); var solution = recognize(recognizer, '/profile/yegor?name=igor');
expect(solution.params).toEqual({'name': 'yegor'}); expect(solution.params).toEqual({'name': 'yegor'});
@ -157,7 +157,7 @@ export function main() {
it('should ignore matrix params for the top-level component', () => { it('should ignore matrix params for the top-level component', () => {
recognizer.config(new Route({path: '/home/:subject', component: DummyCmpA, as: 'user'})); recognizer.config(new Route({path: '/home/:subject', component: DummyCmpA, as: 'User'}));
var solution = recognize(recognizer, '/home;sort=asc/zero;one=1?two=2'); var solution = recognize(recognizer, '/home;sort=asc/zero;one=1?two=2');
expect(solution.params).toEqual({'subject': 'zero', 'two': '2'}); expect(solution.params).toEqual({'subject': 'zero', 'two': '2'});
}); });

View File

@ -43,45 +43,45 @@ export function main() {
it('should generate URLs starting at the given component', () => { it('should generate URLs starting at the given component', () => {
registry.config(RootHostCmp, registry.config(RootHostCmp,
new Route({path: '/first/...', component: DummyParentCmp, as: 'firstCmp'})); new Route({path: '/first/...', component: DummyParentCmp, as: 'FirstCmp'}));
expect(stringifyInstruction(registry.generate(['firstCmp', 'secondCmp'], RootHostCmp))) expect(stringifyInstruction(registry.generate(['FirstCmp', 'SecondCmp'], RootHostCmp)))
.toEqual('first/second'); .toEqual('first/second');
expect(stringifyInstruction(registry.generate(['secondCmp'], DummyParentCmp))) expect(stringifyInstruction(registry.generate(['SecondCmp'], DummyParentCmp)))
.toEqual('second'); .toEqual('second');
}); });
it('should generate URLs that account for redirects', () => { it('should generate URLs that account for redirects', () => {
registry.config( registry.config(
RootHostCmp, RootHostCmp,
new Route({path: '/first/...', component: DummyParentRedirectCmp, as: 'firstCmp'})); new Route({path: '/first/...', component: DummyParentRedirectCmp, as: 'FirstCmp'}));
expect(stringifyInstruction(registry.generate(['firstCmp'], RootHostCmp))) expect(stringifyInstruction(registry.generate(['FirstCmp'], RootHostCmp)))
.toEqual('first/second'); .toEqual('first/second');
}); });
it('should generate URLs in a hierarchy of redirects', () => { it('should generate URLs in a hierarchy of redirects', () => {
registry.config( registry.config(
RootHostCmp, RootHostCmp,
new Route({path: '/first/...', component: DummyMultipleRedirectCmp, as: 'firstCmp'})); new Route({path: '/first/...', component: DummyMultipleRedirectCmp, as: 'FirstCmp'}));
expect(stringifyInstruction(registry.generate(['firstCmp'], RootHostCmp))) expect(stringifyInstruction(registry.generate(['FirstCmp'], RootHostCmp)))
.toEqual('first/second/third'); .toEqual('first/second/third');
}); });
it('should generate URLs with params', () => { it('should generate URLs with params', () => {
registry.config( registry.config(
RootHostCmp, RootHostCmp,
new Route({path: '/first/:param/...', component: DummyParentParamCmp, as: 'firstCmp'})); new Route({path: '/first/:param/...', component: DummyParentParamCmp, as: 'FirstCmp'}));
var url = stringifyInstruction(registry.generate( var url = stringifyInstruction(registry.generate(
['firstCmp', {param: 'one'}, 'secondCmp', {param: 'two'}], RootHostCmp)); ['FirstCmp', {param: 'one'}, 'SecondCmp', {param: 'two'}], RootHostCmp));
expect(url).toEqual('first/one/second/two'); expect(url).toEqual('first/one/second/two');
}); });
it('should generate params as an empty StringMap when no params are given', () => { it('should generate params as an empty StringMap when no params are given', () => {
registry.config(RootHostCmp, new Route({path: '/test', component: DummyCmpA, as: 'test'})); registry.config(RootHostCmp, new Route({path: '/test', component: DummyCmpA, as: 'Test'}));
var instruction = registry.generate(['test'], RootHostCmp); var instruction = registry.generate(['Test'], RootHostCmp);
expect(instruction.component.params).toEqual({}); expect(instruction.component.params).toEqual({});
}); });
@ -89,15 +89,15 @@ export function main() {
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
registry.config( registry.config(
RootHostCmp, RootHostCmp,
new AsyncRoute({path: '/first/...', loader: AsyncParentLoader, as: 'firstCmp'})); new AsyncRoute({path: '/first/...', loader: AsyncParentLoader, as: 'FirstCmp'}));
expect(() => registry.generate(['firstCmp', 'secondCmp'], RootHostCmp)) expect(() => registry.generate(['FirstCmp', 'SecondCmp'], RootHostCmp))
.toThrowError('Could not find route named "secondCmp".'); .toThrowError('Could not find route named "SecondCmp".');
registry.recognize('/first/second', RootHostCmp) registry.recognize('/first/second', RootHostCmp)
.then((_) => { .then((_) => {
expect( expect(
stringifyInstruction(registry.generate(['firstCmp', 'secondCmp'], RootHostCmp))) stringifyInstruction(registry.generate(['FirstCmp', 'SecondCmp'], RootHostCmp)))
.toEqual('first/second'); .toEqual('first/second');
async.done(); async.done();
}); });
@ -105,7 +105,7 @@ export function main() {
it('should throw when generating a url and a parent has no config', () => { it('should throw when generating a url and a parent has no config', () => {
expect(() => registry.generate(['firstCmp', 'secondCmp'], RootHostCmp)) expect(() => registry.generate(['FirstCmp', 'SecondCmp'], RootHostCmp))
.toThrowError('Component "RootHostCmp" has no route config.'); .toThrowError('Component "RootHostCmp" has no route config.');
}); });
@ -233,9 +233,9 @@ export function main() {
it('should throw when linkParams are not terminal', () => { it('should throw when linkParams are not terminal', () => {
registry.config(RootHostCmp, registry.config(RootHostCmp,
new Route({path: '/first/...', component: DummyParentCmp, as: 'first'})); new Route({path: '/first/...', component: DummyParentCmp, as: 'First'}));
expect(() => { registry.generate(['first'], RootHostCmp); }) expect(() => { registry.generate(['First'], RootHostCmp); })
.toThrowError('Link "["first"]" does not resolve to a terminal or async 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', it('should match matrix params on child components and query params on the root component',
@ -256,13 +256,13 @@ export function main() {
it('should generate URLs with matrix and query params', () => { it('should generate URLs with matrix and query params', () => {
registry.config( registry.config(
RootHostCmp, RootHostCmp,
new Route({path: '/first/:param/...', component: DummyParentParamCmp, as: 'firstCmp'})); new Route({path: '/first/:param/...', component: DummyParentParamCmp, as: 'FirstCmp'}));
var url = stringifyInstruction(registry.generate( var url = stringifyInstruction(registry.generate(
[ [
'firstCmp', 'FirstCmp',
{param: 'one', query: 'cats'}, {param: 'one', query: 'cats'},
'secondCmp', 'SecondCmp',
{ {
param: 'two', param: 'two',
sort: 'asc', sort: 'asc',
@ -294,7 +294,7 @@ class DummyCmpB {}
@RouteConfig([ @RouteConfig([
new Redirect({path: '/', redirectTo: '/third'}), new Redirect({path: '/', redirectTo: '/third'}),
new Route({path: '/third', component: DummyCmpB, as: 'thirdCmp'}) new Route({path: '/third', component: DummyCmpB, as: 'ThirdCmp'})
]) ])
class DummyRedirectCmp { class DummyRedirectCmp {
} }
@ -302,23 +302,23 @@ class DummyRedirectCmp {
@RouteConfig([ @RouteConfig([
new Redirect({path: '/', redirectTo: '/second'}), new Redirect({path: '/', redirectTo: '/second'}),
new Route({path: '/second/...', component: DummyRedirectCmp, as: 'secondCmp'}) new Route({path: '/second/...', component: DummyRedirectCmp, as: 'SecondCmp'})
]) ])
class DummyMultipleRedirectCmp { class DummyMultipleRedirectCmp {
} }
@RouteConfig([ @RouteConfig([
new Redirect({path: '/', redirectTo: '/second'}), new Redirect({path: '/', redirectTo: '/second'}),
new Route({path: '/second', component: DummyCmpB, as: 'secondCmp'}) new Route({path: '/second', component: DummyCmpB, as: 'SecondCmp'})
]) ])
class DummyParentRedirectCmp { class DummyParentRedirectCmp {
} }
@RouteConfig([new Route({path: '/second', component: DummyCmpB, as: 'secondCmp'})]) @RouteConfig([new Route({path: '/second', component: DummyCmpB, as: 'SecondCmp'})])
class DummyParentCmp { class DummyParentCmp {
} }
@RouteConfig([new Route({path: '/second/:param', component: DummyCmpB, as: 'secondCmp'})]) @RouteConfig([new Route({path: '/second/:param', component: DummyCmpB, as: 'SecondCmp'})])
class DummyParentParamCmp { class DummyParentParamCmp {
} }

View File

@ -88,7 +88,7 @@ class UserCmp {
@View({ @View({
template: ` template: `
<div> <div>
<a [router-link]="['/detail']">detail view</a> <a [router-link]="['/Detail']">detail view</a>
</div>`, </div>`,
directives: [RouterLink] directives: [RouterLink]
}) })

View File

@ -120,9 +120,9 @@ export function main() {
it('should throw when linkParams does not start with a "/" or "./"', () => { it('should throw when linkParams does not start with a "/" or "./"', () => {
expect(() => router.generate(['firstCmp', 'secondCmp'])) expect(() => router.generate(['FirstCmp', 'SecondCmp']))
.toThrowError( .toThrowError(
`Link "${ListWrapper.toJSON(['firstCmp', 'secondCmp'])}" must start with "/", "./", or "../"`); `Link "${ListWrapper.toJSON(['FirstCmp', 'SecondCmp'])}" must start with "/", "./", or "../"`);
}); });
@ -141,12 +141,12 @@ export function main() {
}); });
it('should generate URLs from the root component when the path starts with /', () => { it('should generate URLs from the root component when the path starts with /', () => {
router.config([new Route({path: '/first/...', component: DummyParentComp, as: 'firstCmp'})]); router.config([new Route({path: '/first/...', component: DummyParentComp, as: 'FirstCmp'})]);
var instruction = router.generate(['/firstCmp', 'secondCmp']); var instruction = router.generate(['/FirstCmp', 'SecondCmp']);
expect(stringifyInstruction(instruction)).toEqual('first/second'); expect(stringifyInstruction(instruction)).toEqual('first/second');
instruction = router.generate(['/firstCmp/secondCmp']); instruction = router.generate(['/FirstCmp/SecondCmp']);
expect(stringifyInstruction(instruction)).toEqual('first/second'); expect(stringifyInstruction(instruction)).toEqual('first/second');
}); });
@ -188,9 +188,9 @@ export function main() {
describe('query string params', () => { describe('query string params', () => {
it('should use query string params for the root route', () => { it('should use query string params for the root route', () => {
router.config( router.config(
[new Route({path: '/hi/how/are/you', component: DummyComponent, as: 'greeting-url'})]); [new Route({path: '/hi/how/are/you', component: DummyComponent, as: 'GreetingUrl'})]);
var instruction = router.generate(['/greeting-url', {'name': 'brad'}]); var instruction = router.generate(['/GreetingUrl', {'name': 'brad'}]);
var path = stringifyInstruction(instruction); var path = stringifyInstruction(instruction);
expect(path).toEqual('hi/how/are/you?name=brad'); expect(path).toEqual('hi/how/are/you?name=brad');
}); });
@ -198,9 +198,9 @@ export function main() {
it('should serialize parameters that are not part of the route definition as query string params', it('should serialize parameters that are not part of the route definition as query string params',
() => { () => {
router.config( router.config(
[new Route({path: '/one/two/:three', component: DummyComponent, as: 'number-url'})]); [new Route({path: '/one/two/:three', component: DummyComponent, as: 'NumberUrl'})]);
var instruction = router.generate(['/number-url', {'three': 'three', 'four': 'four'}]); var instruction = router.generate(['/NumberUrl', {'three': 'three', 'four': 'four'}]);
var path = stringifyInstruction(instruction); var path = stringifyInstruction(instruction);
expect(path).toEqual('one/two/three?four=four'); expect(path).toEqual('one/two/three?four=four');
}); });
@ -209,20 +209,20 @@ export function main() {
describe('matrix params', () => { describe('matrix params', () => {
it('should generate matrix params for each non-root component', () => { it('should generate matrix params for each non-root component', () => {
router.config( router.config(
[new Route({path: '/first/...', component: DummyParentComp, as: 'firstCmp'})]); [new Route({path: '/first/...', component: DummyParentComp, as: 'FirstCmp'})]);
var instruction = var instruction =
router.generate(['/firstCmp', {'key': 'value'}, 'secondCmp', {'project': 'angular'}]); router.generate(['/FirstCmp', {'key': 'value'}, 'SecondCmp', {'project': 'angular'}]);
var path = stringifyInstruction(instruction); var path = stringifyInstruction(instruction);
expect(path).toEqual('first/second;project=angular?key=value'); expect(path).toEqual('first/second;project=angular?key=value');
}); });
it('should work with named params', () => { it('should work with named params', () => {
router.config( router.config(
[new Route({path: '/first/:token/...', component: DummyParentComp, as: 'firstCmp'})]); [new Route({path: '/first/:token/...', component: DummyParentComp, as: 'FirstCmp'})]);
var instruction = var instruction =
router.generate(['/firstCmp', {'token': 'min'}, 'secondCmp', {'author': 'max'}]); router.generate(['/FirstCmp', {'token': 'min'}, 'SecondCmp', {'author': 'max'}]);
var path = stringifyInstruction(instruction); var path = stringifyInstruction(instruction);
expect(path).toEqual('first/min/second;author=max'); expect(path).toEqual('first/min/second;author=max');
}); });
@ -236,7 +236,7 @@ function loader(): Promise<Type> {
class DummyComponent {} class DummyComponent {}
@RouteConfig([new Route({path: '/second', component: DummyComponent, as: 'secondCmp'})]) @RouteConfig([new Route({path: '/second', component: DummyComponent, as: 'SecondCmp'})])
class DummyParentComp { class DummyParentComp {
} }

View File

@ -4,7 +4,7 @@
<ol class="inbox-list"> <ol class="inbox-list">
<li *ng-for="#item of items" class="inbox-item-record"> <li *ng-for="#item of items" class="inbox-item-record">
<a id="item-{{ item.id }}" <a id="item-{{ item.id }}"
[router-link]="['/detailPage', {'id':item.id}]"> [router-link]="['/DetailPage', {'id':item.id}]">
{{ item.subject }}</a> {{ item.subject }}</a>
</li> </li>
</ol> </ol>

View File

@ -1,5 +1,5 @@
<inbox-side-menu class="inbox-aside"> <inbox-side-menu class="inbox-aside">
<a [router-link]="['/inbox']" class="link" [class.active]="inboxPageActive()">Inbox</a> <a [router-link]="['/Inbox']" class="link" [class.active]="inboxPageActive()">Inbox</a>
<a [router-link]="['/drafts']" class="link" [class.active]="draftsPageActive()">Drafts</a> <a [router-link]="['/Drafts']" class="link" [class.active]="draftsPageActive()">Drafts</a>
</inbox-side-menu> </inbox-side-menu>
<router-outlet></router-outlet> <router-outlet></router-outlet>

View File

@ -134,9 +134,9 @@ class DraftsCmp {
@Component({selector: 'inbox-app', viewBindings: [DbService]}) @Component({selector: 'inbox-app', viewBindings: [DbService]})
@View({templateUrl: "inbox-app.html", directives: [RouterOutlet, RouterLink]}) @View({templateUrl: "inbox-app.html", directives: [RouterOutlet, RouterLink]})
@RouteConfig([ @RouteConfig([
new Route({path: '/', component: InboxCmp, as: 'inbox'}), new Route({path: '/', component: InboxCmp, as: 'Inbox'}),
new Route({path: '/drafts', component: DraftsCmp, as: 'drafts'}), new Route({path: '/drafts', component: DraftsCmp, as: 'Drafts'}),
new Route({path: '/detail/:id', component: InboxDetailCmp, as: 'detailPage'}) new Route({path: '/detail/:id', component: InboxDetailCmp, as: 'DetailPage'})
]) ])
export class InboxApp { export class InboxApp {
router: Router; router: Router;

View File

@ -13,6 +13,6 @@
</p> </p>
<span class="btn medium primary"> <span class="btn medium primary">
<a [router-link]="record.draft ? ['../drafts'] : ['../inbox']" class="back-button">Back</a> <a [router-link]="record.draft ? ['../Drafts'] : ['../Inbox']" class="back-button">Back</a>
</span> </span>
</div> </div>

View File

@ -4,7 +4,7 @@
<ol class="inbox-list"> <ol class="inbox-list">
<li *ng-for="#item of items" class="inbox-item-record"> <li *ng-for="#item of items" class="inbox-item-record">
<a id="item-{{ item.id }}" <a id="item-{{ item.id }}"
[router-link]="['/detailPage', {'id':item.id}]">{{ item.subject }}</a> [router-link]="['/DetailPage', {'id':item.id}]">{{ item.subject }}</a>
</li> </li>
</ol> </ol>
</div> </div>