当我们在StartUp.cs中使用UseAngularCliServer进行配置时,我想执行npmScript“ start”或npmScript“ start:fr”,这取决于我以英语还是法语获取应用程序的路径,具体取决于我的usr是http://localhost:4200/en-GB或http://localhost:4200/fr-FR
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
public void ConfigureServices(IServiceCollection services){...}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
....
app.UseStaticFiles();
app.UseMvc(routes =>
{
....
});
/*HERE is when we use Spa*/
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
//I would execute
spa.UseAngularCliServer(npmScript: "start");
//or Execute e.g. depending my route
spa.UseAngularCliserver(npmScript:"start:fr");
}
});
}
}
有可能吗?我无法想象如何。
我会尝试做些类似的事情
if (env.IsDevelopment())
{
string culture = null;
app.Use(async (context, next) =>
{
switch (context.Request.Path.Value)
{
case "/fr-FR":
culture = "fr";
break;
}
await next.Invoke();
});
if (culture!=null)
spa.UseAngularCliServer(npmScript: "start:" + culture);
else
spa.UseAngularCliServer(npmScript: "start");
}
但是,如果我在导航器中更改了网址,请不要执行脚本