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

231
Visualizações
In angular 2 how can I make the canonical tag dynamic per page

In angular 2 how can I make the canonical tag dynamic per page.

This is my index page tag for it:

  <link rel="canonical" href="https://mywebsite.co.uk" />

How can I make it dynamic e.g. if on blog page it should look like this at run time:

  <link rel="canonical" href="https://mywebsite.co.uk/blog" />

I'm using angular version 4, webpack and typescript with ng2-metadata to change the title, description and keywords of all my urls.

I just need the canonical tag to change for the seo google bot.

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

0

I implemented a service that is called in the ngOnInit functions of my page components:

import { Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/common';

@Injectable()
export class LinkService {

  private link: HTMLLinkElement;

  constructor(@Inject(DOCUMENT) private doc) { }

  createLinkForCanonicalURL() {
    if (this.link === undefined) {
      this.link = this.doc.createElement('link');
      this.link.setAttribute('rel', 'canonical');
      this.doc.head.appendChild(this.link);
    }
    this.link.setAttribute('href', this.doc.URL.split('?')[0]);
  }
}

Source: https://www.concretepage.com/angular/angular-title-service-and-canonical-url

about 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