feat(router): add a validation to make sure pathMatch is set correctly
This commit is contained in:
parent
5162fb6d52
commit
3c3e9ddb10
|
@ -542,4 +542,8 @@ function validateNode(route: Route): void {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid route configuration of route '{path: "${route.path}", redirectTo: "${route.redirectTo}"}': please provide 'pathMatch'. ${exp}`);
|
`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'`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,12 @@ describe('config', () => {
|
||||||
validateConfig([<any>{path: '', redirectTo: 'b'}]);
|
validateConfig([<any>{path: '', redirectTo: 'b'}]);
|
||||||
}).toThrowError(/Invalid route configuration of route '{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'/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue