我正在国际化的过程中,一个角11申请。ng serve的情况很好,但我在部署时遇到了问题,因为我无法解决以下问题:
/assets/picture.png的资产(即在/xx/assets/picture.png中转换了xx是en或fr等语言):它们触发了404错误。https://example.com/records/12 )不会触发错误,并自动转换为https://example.com/xx/records/12 (其中xx是en或fr等语言)。angular.json文件包含标准内容:
"i18n": {
"sourceLocale": "fr",
"locales": {
"en": {
"translation": "src/locale/messages.en.xlf"
}
}
}
...
"localize": true
...该应用程序是用ng build --prod --localize用2种语言构建的,它在dist中生成2个en和fr子文件夹,然后我将其部署到服务器根目录下,在下面的.htaccess文件旁边:
RewriteEngine on
RewriteBase /
RewriteRule ^../index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (..) $1/index.html [L]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [R]
RewriteCond %{HTTP:Accept-Language} !^en [NC]
RewriteRule ^$ /fr/ [R](请注意,fr是源和默认区域设置,en是一个翻译)
我设想这个问题来自于.htaccess文件,因为那里没有指定https://example.com/assets/picture.png应该转换为https://example.com/en/assets/picture.png,对于角路由的URL也是如此。
你能告诉我怎么解决这个问题吗?
注意:通过查看生成的网页的源代码,我可以验证它是否包含适当的href,例如对于fr。
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>MyApp</title>
<base href="/fr/">https://stackoverflow.com/questions/71386998
复制相似问题