【发布时间】:2018-07-22 18:24:36
【问题描述】:
我正在尝试在 .NET Core 2.1 中创建一个 Angular 多语言应用程序 用其他成语服务。我使用 app.Map 在我的 Startup.cs 中运行不同的 npmScripts
app.Map("/fr-FR", spaFr =>
{
spaFr.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
spa.Options.DefaultPage = $"/fr-FR/index.html";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start:fr");
}
});
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
spa.Options.DefaultPage = $"/index.html";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
所以
http://localhost:52337 为应用提供英文服务
http://localhost:52337/fr-FR在法国为应用提供服务
但是当我写http://localhost:52337/fr-FR 时,应用程序找不到捆绑文件:styles.a006ff9ecb31fc360851.css、runtime.a66f828dca56eeb90e02.js、polyfills.662173b507c7bb60d452.js 和 main.ddceca57cc95aeab5c91.js
而.NET 找不到文件,因为它在http://localhost:52337/ 中寻找,但文件在http://localhost:52337/fr-FR 中
我的 package.json 有脚本
"start": "ng serve",
"start:fr": "ng serve --serve-path=/ --base-href=/fr-FR --configuration=fr",
我已经在配置中的 angular.json 中添加了
"production-fr": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"outputPath": "dist/fr-FR/",
"i18nFile": "src/i18n/messages.fr.xlf",
"i18nFormat": "xlf",
"i18nLocale": "fr",
"i18nMissingTranslation": "error"
},
"fr": {
"aot": true,
"outputHashing": "all",
"serve-path":"/fr-FR/",
"i18nFile": "src/i18n/messages.fr.xlf",
"i18nFormat": "xlf",
"i18nLocale": "fr",
"i18nMissingTranslation": "error"
}
我认为我在脚本中进行了所有可能的组合,使用或不使用 --serve-path、--deploy-url、--base-href ...但我可以在开发环境中完成这项工作。会发生什么?
【问题讨论】:
标签: angular .net-core-2.1