feat(router): route redirects
This commit is contained in:
2
modules/angular2/src/router/route_config.js
vendored
2
modules/angular2/src/router/route_config.js
vendored
@ -6,7 +6,7 @@ import {List, Map} from 'angular2/src/facade/collection';
|
||||
*
|
||||
* Supported keys:
|
||||
* - `path` (required)
|
||||
* - `component` or `components` (requires exactly one of these)
|
||||
* - `component`, `components`, `redirectTo` (requires exactly one of these)
|
||||
* - `as` (optional)
|
||||
*/
|
||||
export class RouteConfig {
|
||||
|
13
modules/angular2/src/router/route_registry.js
vendored
13
modules/angular2/src/router/route_registry.js
vendored
@ -13,14 +13,14 @@ export class RouteRegistry {
|
||||
}
|
||||
|
||||
config(parentComponent, config) {
|
||||
|
||||
if (!StringMapWrapper.contains(config, 'path')) {
|
||||
throw new BaseException('Route config does not contain "path"');
|
||||
}
|
||||
|
||||
if (!StringMapWrapper.contains(config, 'component') &&
|
||||
!StringMapWrapper.contains(config, 'components')) {
|
||||
throw new BaseException('Route config does not contain "component" or "components"');
|
||||
!StringMapWrapper.contains(config, 'components') &&
|
||||
!StringMapWrapper.contains(config, 'redirectTo')) {
|
||||
throw new BaseException('Route config does not contain "component," "components," or "redirectTo"');
|
||||
}
|
||||
|
||||
var recognizer:RouteRecognizer;
|
||||
@ -33,6 +33,11 @@ export class RouteRegistry {
|
||||
|
||||
config = normalizeConfig(config);
|
||||
|
||||
if (StringMapWrapper.contains(config, 'redirectTo')) {
|
||||
recognizer.addRedirect(StringMapWrapper.get(config, 'path'), StringMapWrapper.get(config, 'redirectTo'));
|
||||
return;
|
||||
}
|
||||
|
||||
var components = StringMapWrapper.get(config, 'components');
|
||||
StringMapWrapper.forEach(components, (component, _) => {
|
||||
this.configFromComponent(component);
|
||||
@ -152,8 +157,6 @@ function normalizeConfig(config:StringMap) {
|
||||
});
|
||||
|
||||
return newConfig;
|
||||
} else if (!StringMapWrapper.contains(config, 'components')) {
|
||||
throw new BaseException('Config does not include a "component" or "components" key.');
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
Reference in New Issue
Block a user