Iñigo
Iñigo

Reputation: 2016

Make Angular routes use index.html base href attribute?

Is there any way to make the angular paths take the base href attribute of the index.html file after building the application, so that if I change the base href value the app makes the requests to another url without building the app again?

I know I can achieve this by adding baseHref to angular.json

"architect": {
   "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
         "baseHref" : "/MyApp/"
      }
   }
}

But I'm trying to avoid rebuilding every time.

I also thought changing my iis site configuration, but I have multiple applications inside my site so updating the site config would break those:

Thanks!

Upvotes: 2

Views: 3965

Answers (2)

NicoGuevaraAtuq
NicoGuevaraAtuq

Reputation: 582

Try the following configuration:

"options": {
          "configurations": {
            "production": {
              "baseHref": "/MyApp/",
              "deployUrl": "/MyApp/"

            }

Upvotes: 1

Dmitriy Ivanko
Dmitriy Ivanko

Reputation: 1075

It is Web server work (not Angular Router). I faced with the same problem with i18n. (Some usefull article for this case: https://medium.com/@feloy/deploying-an-i18n-angular-app-with-angular-cli-fc788f17e358)

1) I build two diferent application with: baseHref="/" and "baseHref": "/fr/".

2) Then config IIS web.config to switch betweeen thouse two application.

Hope its help!

Upvotes: 1

Related Questions