/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { PRIMARY_OUTLET } from './shared'; /** * @param {?} config * @param {?=} parentPath * @return {?} */ export function validateConfig(config, parentPath) { if (parentPath === void 0) { parentPath = ''; } // forEach doesn't iterate undefined values for (var /** @type {?} */ i = 0; i < config.length; i++) { var /** @type {?} */ route = config[i]; var /** @type {?} */ fullPath = getFullPath(parentPath, route); validateNode(route, fullPath); } } /** * @param {?} route * @param {?} fullPath * @return {?} */ function validateNode(route, fullPath) { if (!route) { throw new Error("\n Invalid configuration of route '" + fullPath + "': Encountered undefined route.\n The reason might be an extra comma.\n \n Example: \n const routes: Routes = [\n { path: '', redirectTo: '/dashboard', pathMatch: 'full' },\n { path: 'dashboard', component: DashboardComponent },, << two commas\n { path: 'detail/:id', component: HeroDetailComponent }\n ];\n "); } if (Array.isArray(route)) { throw new Error("Invalid configuration of route '" + fullPath + "': Array cannot be specified"); } if (!route.component && (route.outlet && route.outlet !== PRIMARY_OUTLET)) { throw new Error("Invalid configuration of route '" + fullPath + "': a componentless route cannot have a named outlet set"); } if (route.redirectTo && route.children) { throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and children cannot be used together"); } if (route.redirectTo && route.loadChildren) { throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and loadChildren cannot be used together"); } if (route.children && route.loadChildren) { throw new Error("Invalid configuration of route '" + fullPath + "': children and loadChildren cannot be used together"); } if (route.redirectTo && route.component) { throw new Error("Invalid configuration of route '" + fullPath + "': redirectTo and component cannot be used together"); } if (route.path && route.matcher) { throw new Error("Invalid configuration of route '" + fullPath + "': path and matcher cannot be used together"); } if (route.redirectTo === void 0 && !route.component && !route.children && !route.loadChildren) { throw new Error("Invalid configuration of route '" + fullPath + "'. One of the following must be provided: component, redirectTo, children or loadChildren"); } if (route.path === void 0 && route.matcher === void 0) { throw new Error("Invalid configuration of route '" + fullPath + "': routes must have either a path or a matcher specified"); } if (typeof route.path === 'string' && route.path.charAt(0) === '/') { throw new Error("Invalid configuration of route '" + fullPath + "': path cannot start with a slash"); } if (route.path === '' && route.redirectTo !== void 0 && route.pathMatch === void 0) { var /** @type {?} */ exp = "The default value of 'pathMatch' is 'prefix', but often the intent is to use 'full'."; throw new Error("Invalid configuration of route '{path: \"" + fullPath + "\", redirectTo: \"" + route.redirectTo + "\"}': please provide 'pathMatch'. " + exp); } if (route.pathMatch !== void 0 && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') { throw new Error("Invalid configuration of route '" + fullPath + "': pathMatch can only be set to 'prefix' or 'full'"); } if (route.children) { validateConfig(route.children, fullPath); } } /** * @param {?} parentPath * @param {?} currentRoute * @return {?} */ function getFullPath(parentPath, currentRoute) { if (!currentRoute) { return parentPath; } if (!parentPath && !currentRoute.path) { return ''; } else if (parentPath && !currentRoute.path) { return parentPath + "/"; } else if (!parentPath && currentRoute.path) { return currentRoute.path; } else { return parentPath + "/" + currentRoute.path; } } //# sourceMappingURL=config.js.map