如何在来自 index.html 的 Angular 8 应用程序中动态定义 "base href "?

How to define "base href " dynamically in Angular 8 application from index.html?

如何在来自 index.html 的 Angular 8 应用程序中动态定义 "base href "?

之前用过--base-href,现在不支持了

您可以通过脚本设置 属性 并在 NgModule 中获取它来动态设置 base href。

  //index.html
    <script>
      window['base-url'] = window.location.pathname;
    </script>

并且在您的模块中您需要使用

@NgModule({
  providers: [{provide: APP_BASE_HREF, useValue: window['base-url]}]
})