@@ -20,9 +20,10 @@ import {
2020 BaseException ,
2121 getTypeNameForDebugging
2222} from 'angular2/src/facade/lang' ;
23- import { RouteConfig } from './route_config_impl' ;
23+ import { RouteConfig , AsyncRoute , Route , Redirect , RouteDefinition } from './route_config_impl' ;
2424import { reflector } from 'angular2/src/reflection/reflection' ;
2525import { Injectable } from 'angular2/di' ;
26+ import { normalizeRouteConfig } from './route_config_nomalizer' ;
2627
2728/**
2829 * The RouteRegistry holds route configurations for each component in an Angular app.
@@ -36,8 +37,8 @@ export class RouteRegistry {
3637 /**
3738 * Given a component and a configuration object, add the route to this registry
3839 */
39- config ( parentComponent , config : StringMap < string , any > ) : void {
40- assertValidConfig ( config ) ;
40+ config ( parentComponent , config : RouteDefinition ) : void {
41+ config = normalizeRouteConfig ( config ) ;
4142
4243 var recognizer : RouteRecognizer = this . _rules . get ( parentComponent ) ;
4344
@@ -46,22 +47,13 @@ export class RouteRegistry {
4647 this . _rules . set ( parentComponent , recognizer ) ;
4748 }
4849
49- if ( StringMapWrapper . contains ( config , 'redirectTo' ) ) {
50- recognizer . addRedirect ( config [ 'path' ] , config [ 'redirectTo' ] ) ;
51- return ;
52- }
53-
54- config = StringMapWrapper . merge (
55- config , { 'component' : normalizeComponentDeclaration ( config [ 'component' ] ) } ) ;
50+ var terminal = recognizer . config ( config ) ;
5651
57- var component = config [ 'component' ] ;
58- var terminal = recognizer . addConfig ( config [ 'path' ] , config , config [ 'as' ] ) ;
59-
60- if ( component [ 'type' ] == 'constructor' ) {
52+ if ( config instanceof Route ) {
6153 if ( terminal ) {
62- assertTerminalComponent ( component [ 'constructor' ] , config [ ' path' ] ) ;
54+ assertTerminalComponent ( config . component , config . path ) ;
6355 } else {
64- this . configFromComponent ( component [ 'constructor' ] ) ;
56+ this . configFromComponent ( config . component ) ;
6557 }
6658 }
6759 }
@@ -191,50 +183,6 @@ export class RouteRegistry {
191183}
192184
193185
194- /*
195- * A config should have a "path" property, and exactly one of:
196- * - `component`
197- * - `redirectTo`
198- */
199- var ALLOWED_TARGETS = [ 'component' , 'redirectTo' ] ;
200- function assertValidConfig ( config : StringMap < string , any > ) : void {
201- if ( ! StringMapWrapper . contains ( config , 'path' ) ) {
202- throw new BaseException ( `Route config should contain a "path" property` ) ;
203- }
204- var targets = 0 ;
205- ListWrapper . forEach ( ALLOWED_TARGETS , ( target ) => {
206- if ( StringMapWrapper . contains ( config , target ) ) {
207- targets += 1 ;
208- }
209- } ) ;
210- if ( targets != 1 ) {
211- throw new BaseException (
212- `Route config should contain exactly one 'component', or 'redirectTo' property` ) ;
213- }
214- }
215-
216- /*
217- * Returns a StringMap like: `{ 'constructor': SomeType, 'type': 'constructor' }`
218- */
219- var VALID_COMPONENT_TYPES = [ 'constructor' , 'loader' ] ;
220- function normalizeComponentDeclaration ( config : any ) : StringMap < string , any > {
221- if ( isType ( config ) ) {
222- return { 'constructor' : config , 'type' : 'constructor' } ;
223- } else if ( isStringMap ( config ) ) {
224- if ( isBlank ( config [ 'type' ] ) ) {
225- throw new BaseException (
226- `Component declaration when provided as a map should include a 'type' property` ) ;
227- }
228- var componentType = config [ 'type' ] ;
229- if ( ! ListWrapper . contains ( VALID_COMPONENT_TYPES , componentType ) ) {
230- throw new BaseException ( `Invalid component type '${ componentType } '` ) ;
231- }
232- return config ;
233- } else {
234- throw new BaseException ( `Component declaration should be either a Map or a Type` ) ;
235- }
236- }
237-
238186/*
239187 * Given a list of instructions, returns the most specific instruction
240188 */
0 commit comments