装饰器中不支持'AppRoutingModule'函数表达式的模板编译期间的错误

问题描述 投票:0回答:1

我在Alireza中使用“ CaseInsensitiveMatcher”。问题是当尝试进行产品构建时,出现以下错误

“'urlMatch'引用'CaseInsensitiveMatcher''CaseInsensitiveMatcher'包含src \ app \ providers \ caseInsensitiveMatcher.ts(4,10)处的错误考虑将函数表达式更改为导出的函数“

来自应用程序路由模块的示例代码

    export function urlMatch(str: string) {
    return CaseInsensitiveMatcher(str).apply(this, arguments);
}

const routes: Routes = [

    { matcher: urlMatch('en-ie'), component: HomepageComponent },
    { matcher: urlMatch('en-gb'), component: HomepageComponent },
]

@NgModule({
    imports: [RouterModule.forRoot(routes),SharedModule, AccountModule],
    exports: [RouterModule, SharedModule, AccountModule]
})
export class AppRoutingModule { }

CaseInsensitiveveMatcher代码

import {Route, UrlSegment, UrlSegmentGroup} from '@angular/router';

export function CaseInsensitiveMatcher(url: string) {
  return function(
    segments: UrlSegment[],
    segmentGroup: UrlSegmentGroup,
    route: Route
  ) {
    const matchSegments = url.split('/');
    if (
      matchSegments.length > segments.length ||
      (matchSegments.length !== segments.length && route.pathMatch === 'full')
    ) {
      return null;
    }

    const consumed: UrlSegment[] = [];
    const posParams: {[name: string]: UrlSegment} = {};
    for (let index = 0; index < matchSegments.length; ++index) {
      const segment = segments[index].toString().toLowerCase();
      const matchSegment = matchSegments[index];

      if (matchSegment.startsWith(':')) {
        posParams[matchSegment.slice(1)] = segments[index];
        consumed.push(segments[index]);
      } else if (segment.toLowerCase() === matchSegment.toLowerCase()) {
        consumed.push(segments[index]);
      } else {
        return null;
      }
    }

    return { consumed, posParams };
  };
}

如果有人能告诉我我做错了什么,我将不胜感激?甚至如何解决它。无论哪种方式,感谢您感谢您的阅读时间

Link To Orginal for Context

angular routes angular2-aot
1个回答
0
投票

CaseInsensitiveveMatcher返回一个匿名函数,但是不幸的是Angular在AOT中不允许这样的动态代码。您可以做的是重新设计解决方案,以便仅使用命名的导出函数,而无需涉及匿名函数。

© www.soinside.com 2019 - 2024. All rights reserved.