Nat Webb
Nat Webb

Reputation: 708

Angular 2 Base Href not applied

I've built an app using Angular 2 RC 1. The various environments it will be deployed to have different URL base paths (locally it is localhost:12345/, on the dev server it may be 192.168.1.1/myapp, on QA it may be 192.168.2.2/testapp, etc.). I'd like to use the tag to handle these differences, telling Angular to look in the root folder locally, in the myapp folder for dev, in the testapp folder for QA, and so on.

However the base tag seems to be completely ignored by Angular. I am setting it successfully, and when I view the page source of my app I see it as expected. Angular always looks for files in the root folder, though, even when a base href is set.

My tag looks like this:

<head>
  <base href="/myapp">     
  etc...

It's the first tag inside the head. My expectation is that Angular should look for files in localhost:12345/myapp. However it just uses localhost:12345/. Is my understanding of this tag wrong, or do I have an error?

(As a side note, I'm pretty sure I can't set the base url when Angular is bootstrapping because I need to pull it from a .NET web.config file. I'm doing this via the ViewBag and can confirm that it is populating correctly.)

Upvotes: 2

Views: 1837

Answers (1)

Nat Webb
Nat Webb

Reputation: 708

Aha, apparently it needed to be

<base href="/myapp/">

with a slash on both sides!

Upvotes: 6

Related Questions