使 Angular 路由使用 index.html 基本 href 属性?

Make Angular routes use index.html base href attribute?

有什么方法可以让 angular 路径在构建应用程序后采用 index.html 文件的 base href 属性,这样如果我更改 base href应用程序向另一个 url 发出请求而无需再次构建该应用程序的价值?

我知道我可以通过将 baseHref 添加到 angular.json

来实现这一点
"architect": {
   "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
         "baseHref" : "/MyApp/"
      }
   }
}

但我尽量避免每次都重建。

我也想更改我的 iis 站点配置,但我的站点中有多个应用程序,因此更新站点配置会破坏这些:

谢谢!

它是 Web 服务器工作(不是 Angular 路由器)。我遇到了与 i18n 相同的问题。 (一些对这种情况有用的文章:https://medium.com/@feloy/deploying-an-i18n-angular-app-with-angular-cli-fc788f17e358

1) 我构建了两个不同的应用程序:baseHref="/" 和 "baseHref": "/fr/".

2) 然后配置 IIS web.config 以在两个应用程序之间切换。

希望对您有所帮助!

尝试以下配置:

"options": {
          "configurations": {
            "production": {
              "baseHref": "/MyApp/",
              "deployUrl": "/MyApp/"

            }