【发布时间】:2020-09-04 16:56:39
【问题描述】:
我正在开发一个支持 i18n 的 Angular 10 应用程序,我想在 Microsoft IIS 上部署此应用程序,法语版本为 https://example.com/admin/fr,英语版本为 https://example.com/admin/en-US
在文件“index.html”中,我设置了: 在文件“angular.json”中,我添加了:
"i18n": {
"sourceLocale": "en-US",
"locales": {
"fr": {
"translation": "src/locale/messages.fr.xlf"
}
}
},
在环境文件中,我添加了:baseHref: '/admin'
当我在文件“angular.json”中使用选项:“localize”:[“fr”] 进行编译时,我在位于 https://localhost:4200/admin 的开发服务器上获得了一个正常工作的法语应用程序
当我在文件“angular.json”中使用选项:“localize”:[“en-US”] 进行编译时,我在位于 https://localhost:4200/admin 的开发服务器上获得了一个工作英语应用程序
我已阅读 https://angular.io/guide/i18n#deploy-locales 和 https://angular.io/guide/deployment#server-configuration 的 Angular 文档,了解如何在 IIS 上进行生产部署。
我已经设置了上面提到的重写规则,在文件“angular.json”中设置了“localize”:true 以在一个构建中获取所有本地化应用程序,并且,当我在 Windows 上的 MyEclipse 中开发时,我运行构建使用命令: MSYS_NO_PATHCONV=1 node_modules/.bin/ng build --prod --base-href "/admin/"
“fr”和“en-US”文件夹在“dist”文件夹中生成良好,我将它们复制到我的 IIS 网站的“admin”文件夹下。
当我转到https://example.com/admin/fr 时,我在浏览器控制台中收到此错误:错误:无法匹配任何路由。网址段:“fr”
当我转到https://example.com/admin/en-US 时,我在浏览器控制台中收到相同的错误:错误:无法匹配任何路由。 URL 段:'en-US'
我在 Angular 文档中或通过谷歌搜索几个小时都没有找到任何有价值的信息来解决这个问题,因此非常感谢任何帮助。
【问题讨论】:
-
你可以尝试设置iis URL重写规则:
<rule name="AngularJS Routes" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="/admin/" /> </rule> -
当我部署未本地化的 Angular 应用程序时,我已经使用了这个重写规则,它工作正常。不幸的是,它不适用于本地化的应用程序。
-
你可以参考这个链接:stackoverflow.com/a/49898662
-
我找到了这个解决方案,但只有当您的应用程序部署在您网站的根文件夹下时才可以,而不是部署在子文件夹下,这是我需要的。我花了一些时间来寻找如何在 Angular 中配置基本 href 并在 IIS 中重写规则,这就是为什么我发布了如何做到这一点以使其工作。
标签: angular iis internationalization