Currently, I am working with Angular 9 and facing an issue while generating dynamic routes values during runtime. I have implemented a ComplexUrlRouter to achieve this functionality and integrated it into my Route configuration. However, I encountered the following error:
Error: src/app/app.module.ts(33,45): Error during template compile of 'AppRoutes' Expression form not supported. src/app/utility/complex.url.matcher.ts(4,10): Error during template compile of 'ComplexUrlMatcher' Function expressions are not supported in decorators Consider changing the function expression into an exported function.
Here is a snippet from my app.module.ts file:
export const AppRoutes: Routes = [
{ path: '', component: HomeComponent, pathMatch: 'full' },
{
path: 'blog/:id',
component: ArticleComponent,
children: [
{
path: '',
component: ArticleComponent
},
{
matcher: ComplexUrlMatcher("title", /[a-zA-Z0-9]+/),
component: ArticleComponent
},
]
},{
path:'add-blog',component:AddPostComponent
},
{
path:'category/:id',
component:MenuDetailsComponent
},
{ path: '**', redirectTo: '' }
];
And here is part of my complex.url.matcher.ts file:
import { UrlSegment, UrlSegmentGroup, Route } from '@angular/router';
export function ComplexUrlMatcher(paramName: string, regex: RegExp) {
// Function implementation goes here
}
I have tried researching on StackOverflow for a solution but haven't been able to find one that resolves my issue. The Angular Docs URL https://angular.io/guide/aot-compiler#no-arrow-functions mentions that "In version 5 and later, the compiler automatically performs this rewriting while emitting the .js file." However, even though I am using Angular 9, the error persists.