ng build --prod --localize 时更改角度基本 href

ald*_*ldo 3 localization angular-i18n angular

情况

我创建了一个具有国际化(i18n)的 Angular 应用程序。我想在子域中托管不同版本,例如:

  • en.myexample.com
  • es.myexample.com

问题

当我使用命令时, src/app/index.hml 中的ng build --prod --localize标签基本 href添加了语言,例如:

  • <base href="/en/">
  • <base href="/es/">

我想要的是

生成每个版本<base href="/">

Mar*_*wak 8

您可以在 angular.json 文件中为每个语言环境配置基本 href。

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "projects": {
    "my-app": {
      "projectType": "application",
      "...",
      "i18n": {
        "sourceLocale": {"code": "en-US", "baseHref": ""},
        "locales": {
          "de": {"translation": "", "baseHref": ""},
          "de-CH": {"translation": "", "baseHref": ""},
          "en-GB": {"translation": "", "baseHref": ""},
          "fr-FR": {"translation": "", "baseHref": ""},
        }
      },
Run Code Online (Sandbox Code Playgroud)

请参阅https://angular.io/guide/i18n#localize-confighttps://github.com/angular/angular-cli/blob/b90c04db16b9dba85bc7689f205f4e0e4217d772/packages/angular/cli/lib/config/schema.json#L429 -L432了解更多信息。