Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

457
Visualizações
What is the difference between HTML base href and Angular APP_BASE_HREF?

I'm working on an Angular app where I'm faced with setting an HTML base href value, and/or an APP_BASE_HREF value.

What is the difference and relation between these?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In general, you should only have to set the <base href>.

Exceptions are if you do not have access to the index.html or you want the HTML5 style URLs to be different from where you are serving the Angular files (then you need to provide the APP_BASE_HREF).

What is the difference and relation between these?

The <base href> is used as the default base URL (see source code) when generating HTML5 style URLs for your web app. Additionally, it "specifies a base path for resolving relative URLs to assets such as images, scripts, and style sheets," namely your Angular distribution. Since <base href> is just a HTML element, you can see the Mozilla docs for details and see the community wiki for implications.

If for some reason you fall into the above two exceptions, you can provide the APP_BASE_HREF instead, which is solely used for routing purposes (using the PathLocationStrategy) and does not set or interact with the <base href>.

Summary

  1. <base href> is used as the base URL for routing when APP_BASE_HREF is NOT set.
  2. Setting a combination of <base href> and APP_BASE_HREF can be used for deployment scenarios in which the displayed URL and actual location where files are being served are different.
  3. In the case you don't have access to the index.html, the APP_BASE_HREF must be set if using the PathLocationStrategy.

Further reading

  • https://angular.io/guide/router#base-href-1
  • https://angular.io/guide/deployment#the-base-tag
  • https://angular.io/api/common/APP_BASE_HREF
  • https://angular.io/api/common/PathLocationStrategy#description
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda