
Member-only story
How to extract the base HREF in Angular?
Using the location strategy one might get the base HREF passed in the ng build command.
It turns out there is the APP_BASE_HREF
injection token provided out of the box with Angular but if you try and inject it:
You get an error, claiming no one provided it!
NullInjectorError: No provider for InjectionToken appBaseHref!
When we build our app we can specify the base HREF for it:
For example:ng build --base-href /admin
will build our app and instruct it to use base HREF of /admin
That could be useful if the administration part of the app as a separately deployed app under the same domain as our main app.
In order to use that in our app’s logic we can: