angularangular5

How to get base URL in Angular 5?


My current URL is http://localhost:4200/test/dashboard.

I want to print base URL i.e http://localhost:4200 using Angular 5 features.


Solution

  • console.log(location);

    console.log(location.href);

    to get base url : console.log(location.origin);