我正在探索在ASP.NET MVC应用程序中使用Edge.js在服务器端渲染Angular 2的可能性。
我知道Angular Universal Starter Kit包含这个等式的一部分:https://github.com/alexpods/angular2-universal-starter
但是,它使用的是Node.js服务器。我宁愿不在现有的IIS服务器上添加一个Node.js服务器作为额外的Web服务器。我的想法是我可以使用Edge.js在服务器端执行Angular的渲染(即,运行必要的JavaScript来生成标记)。
我是Angular 2的新手,所以为我准备一个例子并运行起来并非易事。基于这个封闭的问题,我说目前还没有努力增加对Edge.js的支持(虽然它在某个时候被考虑):https://github.com/angular/universal/issues/40
是否有人知道是否可以使用ASP.NET MVC应用程序中的Edge.js在服务器端渲染Angular?
顺便说一下,我坚持使用.NET 4.5.2(Umbraco需要它),所以我无法转移到.NET Core并使用它:https://github.com/MarkPieszak/aspnetcore-angular2-universal
答案 0 :(得分:0)
您可以使用Microsoft的SpaServices软件包。在内部,此程序包会将呼叫转发到节点服务器,但您不必在asp.net核心服务器之上运行节点。
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
spa.UseSpaPrerendering(options =>
{
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
options.BootModuleBuilder = env.IsDevelopment()
? new AngularCliBuilder(npmScript: "build:ssr")
: null;
options.ExcludeUrls = new[] { "/sockjs-node" };
});
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});