Search code examples
angulariisangular-routing

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:

  • Site
    • Application 1
    • Application 2
    • MyApp

Thanks!


Solution

  • 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!