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

5k views Asked by At

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

Earlier I used --base-href, but now it is not supported.

1

There are 1 answers

0
Sam On BEST ANSWER

You can set base href dynamically by setting the property through script and getting it in NgModule.

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

And in your module you need to use

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