2016-06-08 11:13:41 -07:00
|
|
|
import {Type} from '@angular/core';
|
2016-05-23 16:14:23 -07:00
|
|
|
|
|
|
|
export type RouterConfig = Route[];
|
|
|
|
|
|
|
|
export interface Route {
|
|
|
|
path?: string;
|
2016-06-14 14:55:59 -07:00
|
|
|
terminal?: boolean;
|
2016-06-08 16:14:26 -07:00
|
|
|
component?: Type|string;
|
2016-05-23 16:14:23 -07:00
|
|
|
outlet?: string;
|
2016-06-07 09:50:35 -07:00
|
|
|
canActivate?: any[];
|
|
|
|
canDeactivate?: any[];
|
2016-06-08 16:14:26 -07:00
|
|
|
redirectTo?: string;
|
2016-05-23 16:14:23 -07:00
|
|
|
children?: Route[];
|
2016-06-16 14:36:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function validateConfig(config: RouterConfig): void {
|
|
|
|
config.forEach(validateNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateNode(route: Route): void {
|
|
|
|
if (!!route.redirectTo && !!route.children) {
|
|
|
|
throw new Error(
|
|
|
|
`Invalid configuration of route '${route.path}': redirectTo and children cannot be used together`);
|
|
|
|
}
|
|
|
|
if (!!route.redirectTo && !!route.component) {
|
|
|
|
throw new Error(
|
|
|
|
`Invalid configuration of route '${route.path}': redirectTo and component cannot be used together`);
|
|
|
|
}
|
|
|
|
if (route.path === undefined) {
|
|
|
|
throw new Error(`Invalid route configuration: routes must have path specified`);
|
|
|
|
}
|
|
|
|
if (route.path.startsWith('/')) {
|
|
|
|
throw new Error(`Invalid route configuration of route '/a': path cannot start with a slash`);
|
|
|
|
}
|
2016-05-23 16:14:23 -07:00
|
|
|
}
|