File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ export class RouteRecognizer {
4444 config ( config : RouteDefinition ) : boolean {
4545 var handler ;
4646
47+ if ( isPresent ( config . as ) && config . as [ 0 ] . toUpperCase ( ) != config . as [ 0 ] ) {
48+ var suggestedAlias = config . as [ 0 ] . toUpperCase ( ) + config . as . substring ( 1 ) ;
49+ throw new BaseException (
50+ `Route '${ config . path } ' with alias '${ config . as } ' does not begin with an uppercase letter. Route aliases should be CamelCase like '${ suggestedAlias } '.` ) ;
51+ }
52+
4753 if ( config instanceof AuxRoute ) {
4854 handler = new SyncRouteHandler ( config . component , config . data ) ;
4955 let path = config . path . startsWith ( '/' ) ? config . path . substring ( 1 ) : config . path ;
Original file line number Diff line number Diff line change @@ -144,6 +144,20 @@ export function main() {
144144 async . done ( ) ;
145145 return null ;
146146 } ) } ) ) ;
147+
148+ it ( 'should throw if a config has an invalid alias name' ,
149+ inject (
150+ [ AsyncTestCompleter ] ,
151+ ( async ) => {
152+ bootstrap ( BadAliasCmp ,
153+ [ bind ( ROUTER_PRIMARY_COMPONENT ) . toValue ( BadAliasCmp ) , testBindings ] )
154+ . catch ( ( e ) => {
155+ expect ( e . originalException )
156+ . toContainError (
157+ `Route '/child' with alias 'child' does not begin with an uppercase letter. Route aliases should be CamelCase like 'Child'.` ) ;
158+ async . done ( ) ;
159+ return null ;
160+ } ) } ) ) ;
147161 } ) ;
148162}
149163
@@ -201,6 +215,12 @@ class HierarchyAppCmp {
201215class WrongConfigCmp {
202216}
203217
218+ @Component ( { selector : 'app-cmp' } )
219+ @View ( { template : `root { <router-outlet></router-outlet> }` , directives : ROUTER_DIRECTIVES } )
220+ @RouteConfig ( [ { path : '/child' , component : HelloCmp , as : 'child' } ] )
221+ class BadAliasCmp {
222+ }
223+
204224@Component ( { selector : 'app-cmp' } )
205225@View ( { template : `root { <router-outlet></router-outlet> }` , directives : ROUTER_DIRECTIVES } )
206226@RouteConfig ( [
Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ export function main() {
127127 } ) ;
128128
129129
130+ it ( 'should throw if the route alias is not CamelCase' , ( ) => {
131+ expect ( ( ) => recognizer . config (
132+ new Route ( { path : 'app/user/:name' , component : DummyCmpA , as : 'user' } ) ) )
133+ . toThrowError (
134+ `Route 'app/user/:name' with alias 'user' does not begin with an uppercase letter. Route aliases should be CamelCase like 'User'.` ) ;
135+ } ) ;
136+
137+
130138 describe ( 'params' , ( ) => {
131139 it ( 'should recognize parameters within the URL path' , ( ) => {
132140 recognizer . config ( new Route ( { path : 'profile/:name' , component : DummyCmpA , as : 'User' } ) ) ;
You can’t perform that action at this time.
0 commit comments