Instantiating a class in my route file gives the following error: Function calls are not supported in decorators

Instantiating a class in my route file gives the following error: Function calls are not supported in decorators

我正在构建一个复杂的多步骤申请表,申请流程会根据用户给出的答案而变化。我有一个 class,其中包含我所有路由的枚举,并且这个 class 可以在我的整个应用程序中以不同的 classes 访问。 因为这个 class 是唯一保存所有不同路径值的地方,所以我在我的路由文件中实例化它并定义我的路径,如下所示:

    const enums = new MortgageFormEnums();
    export const mortgageFormRoutes = [
    {
     path: 'mortgage',
     component: MortgageComponent,
     children: [
      {
       path: enums.routes.properties[enums.routes.start].url,
       component: StartComponent
      },
      {
       path: enums.routes.properties[enums.routes.whatsUp].url,
       component: WhatsUpComponent
      },
      etc...
    }
    ];

当我使用 AoT 为 prod 构建我的应用程序时,出现错误: src\app\mortgage\mortgage-form.module.ts(42,27) 中的错误:'MortgageFormModule' 的模板编译期间出错 装饰器不支持函数调用,但在 'mortgageFormRoutes' 中调用了 'MortgageFormEnums' 'mortgageFormRoutes' 呼叫 'MortgageFormEnums'.

理想情况下,我希望将路由路径作为枚举保存在一个文件中,以便我可以在应用程序的其他部分访问它。有什么方法可以实现这一点,而不是在路由文件中硬编码我的路径吗?

如有任何建议,我们将不胜感激,谢谢。

装饰器不存在于 运行 时间,因此您不能 运行 在元数据中编码。您可以简单地导出变量而不是 class 并导入它。

export const sharedStuff = { foo:1 };