Angular6种多语言和.NET Core 2.1

Angular 6 multi-language and .NET Core 2.1

我正在尝试在 .NET Core 2.1 中制作一个 Angular 多语言应用程序 服务于他人的成语。我在 Startup.cs

中使用 app.Map 到 运行 不同的 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、运行time.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 ...但我可以做到这一点在开发环境中。会发生什么?

感谢

解决方法很简单,使用serve-path=/,并且不要忘记--base-href中的/final

所以 package.json 中的脚本变成

"scripts": {
    ...
    "start": "ng serve",
    "start:fr": "ng serve --base-href=/fr-FR/ --configuration=fr --serve-path=/",
    ...
  },