如何从index.html在Angular 8应用程序中动态定义“ base href”?

问题描述 投票:0回答:1

如何从index.html在Angular 8应用程序中动态定义“ base href”?

我以前使用过--base-href,但现在不支持。

angular angular-cli base-url angular-cli-v8
1个回答
0
投票

您可以通过脚本设置属性并将其放入NgModule中来动态设置基本href。

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

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

@NgModule({
  providers: [{provide: APP_BASE_HREF, useValue: window['base-url]}]
})
© www.soinside.com 2019 - 2024. All rights reserved.