防止 Angular 使用 langcode 更新基本 href
Prevent Angular from updating base href with langcode
我对 angular v9 有疑问。我已经在我的应用程序中实现了 i18n 本地化功能。当我尝试在某个位置构建我的应用程序时,它会不断地将子文件夹添加到基本 href 路径(但我想将文件保留在子文件夹中)。
有什么方法可以防止将语言环境添加到基本 href url 中吗?
复制步骤:
- 生成虚拟项目[=11=]。
- 构建生产配置
ng build --prod --localize
。
- 文件内置于
dist/en-us/
文件夹中,但 index.html
有 <base href="/en-US/">
.
有什么方法可以强制 angular 停止将语言代码添加到基本 href 中吗?
这会使所有应用程序链接都包含语言代码,这是不希望的。
我的部署配置为根据目录将应用程序部署到不同的位置,每个位置都在根目录下。
- hxxp://app.fr/ 根目录在
/fr/
文件夹
- hxxp://app.de/ 根目录在
/de/
文件夹
发布我的解决方案,但这会破坏 Angular v.9.
的新功能
解决方案是不使用 --localize
标志。
所以我删除了定义:
"i18n": {
"sourceLocale": "de",
"locales": {
"fr": "src/app/locale/messages.fr.xlf",
}
然后我在下面创建了自定义配置:
"configurations": {
"fr": {
"i18nFile": "src/app/locale/messages.fr.xlf",
"i18nLocale": "fr",
"outputPath": "dist/fr"
}
刚刚打了电话:
ng build --configuration=fr
但这很难看.. 所以等待更好的想法:)
你可以用这个覆盖 baseHref:
"locales": {
"de": {
"translation": "src/locale/messages.de.xlf",
"baseHref": "/"
},
....
}
我遇到了同样的问题,并在这个问题中找到了解决方案:
https://github.com/angular/angular-cli/issues/17260
您必须为每个语言环境和您的 sourceLocale 编写 baseHref
"i18n": {
"sourceLocale": {
"code": "en",
"baseHref": ""
},
"locales": {
"fr": {
"baseHref": "",
"translation": "src/locale/messages.fr.xlf"
}
}
}
在 Dockerfile 中:
运行 sed -i "s/
我对 angular v9 有疑问。我已经在我的应用程序中实现了 i18n 本地化功能。当我尝试在某个位置构建我的应用程序时,它会不断地将子文件夹添加到基本 href 路径(但我想将文件保留在子文件夹中)。 有什么方法可以防止将语言环境添加到基本 href url 中吗?
复制步骤:
- 生成虚拟项目[=11=]。
- 构建生产配置
ng build --prod --localize
。 - 文件内置于
dist/en-us/
文件夹中,但index.html
有<base href="/en-US/">
.
有什么方法可以强制 angular 停止将语言代码添加到基本 href 中吗? 这会使所有应用程序链接都包含语言代码,这是不希望的。
我的部署配置为根据目录将应用程序部署到不同的位置,每个位置都在根目录下。
- hxxp://app.fr/ 根目录在
/fr/
文件夹 - hxxp://app.de/ 根目录在
/de/
文件夹
发布我的解决方案,但这会破坏 Angular v.9.
的新功能解决方案是不使用 --localize
标志。
所以我删除了定义:
"i18n": {
"sourceLocale": "de",
"locales": {
"fr": "src/app/locale/messages.fr.xlf",
}
然后我在下面创建了自定义配置:
"configurations": {
"fr": {
"i18nFile": "src/app/locale/messages.fr.xlf",
"i18nLocale": "fr",
"outputPath": "dist/fr"
}
刚刚打了电话:
ng build --configuration=fr
但这很难看.. 所以等待更好的想法:)
你可以用这个覆盖 baseHref:
"locales": {
"de": {
"translation": "src/locale/messages.de.xlf",
"baseHref": "/"
},
....
}
我遇到了同样的问题,并在这个问题中找到了解决方案:
https://github.com/angular/angular-cli/issues/17260
您必须为每个语言环境和您的 sourceLocale 编写 baseHref
"i18n": {
"sourceLocale": {
"code": "en",
"baseHref": ""
},
"locales": {
"fr": {
"baseHref": "",
"translation": "src/locale/messages.fr.xlf"
}
}
}
在 Dockerfile 中:
运行 sed -i "s/