I'm trying to use a closure to pass parameters to the router matcher.
export function componentMatcher(component) {
return (url) => {
// check some condition using component
return {
consumed: url
};
return null;
}
};
RouterModule.forChild([
{
matcher: componentMatcher('foo'),
redirectTo: 'foo'
This fails when compiling to AOT with:
ERROR in Error during template compile of 'ComponentPageModule'
Function expressions are not supported in decorators in 'ɵ0'
'ɵ0' contains the error at src/app/example-components/component-page/component-page.module.ts(31,30)
Consider changing the function expression into an exported function.
Without the parameter requirement it's pretty simple to fix:
export function componentMatcher(url) => {
// check some condition using component
return {
consumed: url
};
return null;
}
How can I pass a parameter and make this AOT compliant?