Angular4-路由器模块提供程序AOT

Angular4-路由器模块提供程序AOT,angular,aot,Angular,Aot,这是我对路由器提供商的声明: @NgModule({ imports: [RouterModule.forRoot(RoutesFactory.buildRoutes())], exports: [RouterModule] }) export class RouterModuleProvider { }; 在AOT中编译时,出现以下错误: 静态解析符号值时遇到错误。调用函数 不支持“getRoutes”函数调用。考虑更换 引用导出函数的函数或lambda,解析 符号Route

这是我对路由器提供商的声明:

@NgModule({
    imports: [RouterModule.forRoot(RoutesFactory.buildRoutes())],
    exports: [RouterModule]
})
export class RouterModuleProvider { };
在AOT中编译时,出现以下错误:

静态解析符号值时遇到错误。调用函数 不支持“getRoutes”函数调用。考虑更换 引用导出函数的函数或lambda,解析 符号RouterModuleProvider

以下是RouteFactory.buildRoutes的内容

static buildRoutes() {
    let returnRoutes: Routes = [
        { path: '', redirectTo: '/login', pathMatch: 'full' },
        { path: 'login', component: ViewsModule.LoginViewComponent }
    ];

    let appendRoutes = (items: MenuItem[], routes: Routes) => {
        for (let item of items) {
            let route: Route = {
                path: item.Path, component: item.Component, children: []
            };

            if (item.Children != null)
                appendRoutes(item.Children, route.children)

            routes.push(route);
        }
    };

    appendRoutes(RoutesFactory.getMenus(), returnRoutes);

    return returnRoutes;

}
getMenus返回对象的静态内部数组。没有从后端加载任何内容


有什么办法可以解决这个问题吗?

不幸的是,正如错误所暗示的那样,@NgModule中元数据的所有内容。。。声明必须是静态可解析的。这意味着在buildRoutes函数中不能有任何逻辑,只有静态声明


但是,似乎有一种替代方法专门用于动态定义路由。请参阅以下答案:

RouteFactory.buildRoutes中有什么内容?我编辑了自己的问题,以便提供有关问题的更多详细信息。这看起来是一种非常奇怪的aot路由方式。你这样做的原因是什么?它指向错误中的函数“getRoutes”,你在哪里调用>@mast3rd3mon?原因是我基于菜单对象创建路由。这是唯一的原因。我愿意接受任何建议。我会看看你的建议。谢谢你的提示。