2

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
  • 1
    As far as I can tell from the documentation, —base-href still works.. is it not setting it in index.html in your dist folder? Commented Dec 11, 2019 at 18:17

1 Answer 1

4

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']}]
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.