1 | "use strict";
|
2 | var exceptions_1 = require('../facade/exceptions');
|
3 | var lang_1 = require('../facade/lang');
|
4 | var route_config_decorator_1 = require('./route_config_decorator');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function normalizeRouteConfig(config, registry) {
|
13 | if (config instanceof route_config_decorator_1.AsyncRoute) {
|
14 | var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
|
15 | return new route_config_decorator_1.AsyncRoute({
|
16 | path: config.path,
|
17 | loader: wrappedLoader,
|
18 | name: config.name,
|
19 | data: config.data,
|
20 | useAsDefault: config.useAsDefault
|
21 | });
|
22 | }
|
23 | if (config instanceof route_config_decorator_1.Route || config instanceof route_config_decorator_1.Redirect || config instanceof route_config_decorator_1.AuxRoute) {
|
24 | return config;
|
25 | }
|
26 | if ((+!!config.component) + (+!!config.redirectTo) + (+!!config.loader) != 1) {
|
27 | throw new exceptions_1.BaseException("Route config should contain exactly one \"component\", \"loader\", or \"redirectTo\" property.");
|
28 | }
|
29 | if (config.loader) {
|
30 | var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
|
31 | return new route_config_decorator_1.AsyncRoute({
|
32 | path: config.path,
|
33 | loader: wrappedLoader,
|
34 | name: config.name,
|
35 | data: config.data,
|
36 | useAsDefault: config.useAsDefault
|
37 | });
|
38 | }
|
39 | if (config.aux) {
|
40 | return new route_config_decorator_1.AuxRoute({ path: config.aux, component: config.component, name: config.name });
|
41 | }
|
42 | if (config.component) {
|
43 | if (typeof config.component == 'object') {
|
44 | var componentDefinitionObject = config.component;
|
45 | if (componentDefinitionObject.type == 'constructor') {
|
46 | return new route_config_decorator_1.Route({
|
47 | path: config.path,
|
48 | component: componentDefinitionObject.constructor,
|
49 | name: config.name,
|
50 | data: config.data,
|
51 | useAsDefault: config.useAsDefault
|
52 | });
|
53 | }
|
54 | else if (componentDefinitionObject.type == 'loader') {
|
55 | return new route_config_decorator_1.AsyncRoute({
|
56 | path: config.path,
|
57 | loader: componentDefinitionObject.loader,
|
58 | name: config.name,
|
59 | data: config.data,
|
60 | useAsDefault: config.useAsDefault
|
61 | });
|
62 | }
|
63 | else {
|
64 | throw new exceptions_1.BaseException("Invalid component type \"" + componentDefinitionObject.type + "\". Valid types are \"constructor\" and \"loader\".");
|
65 | }
|
66 | }
|
67 | return new route_config_decorator_1.Route(config);
|
68 | }
|
69 | if (config.redirectTo) {
|
70 | return new route_config_decorator_1.Redirect({ path: config.path, redirectTo: config.redirectTo });
|
71 | }
|
72 | return config;
|
73 | }
|
74 | exports.normalizeRouteConfig = normalizeRouteConfig;
|
75 | function wrapLoaderToReconfigureRegistry(loader, registry) {
|
76 | return function () {
|
77 | return loader().then(function (componentType /** TODO #9100 */) {
|
78 | registry.configFromComponent(componentType);
|
79 | return componentType;
|
80 | });
|
81 | };
|
82 | }
|
83 | function assertComponentExists(component, path) {
|
84 | if (!lang_1.isType(component)) {
|
85 | throw new exceptions_1.BaseException("Component for route \"" + path + "\" is not defined, or is not a class.");
|
86 | }
|
87 | }
|
88 | exports.assertComponentExists = assertComponentExists;
|
89 |
|
\ | No newline at end of file |