【问题标题】:Change angular base href when ng build --prod --localizeng build --prod --localize 时更改 angular base href
【发布时间】:2020-05-12 13:47:13
【问题描述】:

情况

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

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

问题

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

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

我想要什么

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

【问题讨论】:

    标签: angular localization angular-i18n


    【解决方案1】:

    您可以在 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": ""},
            }
          },
    

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

    【讨论】:

    • 配置 "sourceLocale": {"code": "en-US", "baseHref": ""} 拯救我的一天。非常感谢@Martin
    猜你喜欢
    • 2018-05-21
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多