feat(router): add a validation to make sure pathMatch is set correctly

This commit is contained in:
vsavkin 2016-07-29 09:59:50 -07:00
parent 5162fb6d52
commit 3c3e9ddb10
2 changed files with 10 additions and 0 deletions

View File

@ -542,4 +542,8 @@ function validateNode(route: Route): void {
throw new Error(
`Invalid route configuration of route '{path: "${route.path}", redirectTo: "${route.redirectTo}"}': please provide 'pathMatch'. ${exp}`);
}
if (route.pathMatch !== undefined && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') {
throw new Error(
`Invalid configuration of route '${route.path}': pathMatch can only be set to 'prefix' or 'full'`);
}
}

View File

@ -74,6 +74,12 @@ describe('config', () => {
validateConfig([<any>{path: '', redirectTo: 'b'}]);
}).toThrowError(/Invalid route configuration of route '{path: "", redirectTo: "b"}'/);
});
it('should throw when pathPatch is invalid', () => {
expect(() => { validateConfig([{path: 'a', pathMatch: 'invalid', component: 'b'}]); })
.toThrowError(
/Invalid configuration of route 'a': pathMatch can only be set to 'prefix' or 'full'/);
});
});
});