Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Solution problem: adding SEO meta tags to <head> #454

Closed
1 of 3 tasks
kaaboeld opened this issue Jun 25, 2016 · 6 comments
Closed
1 of 3 tasks

Solution problem: adding SEO meta tags to <head> #454

kaaboeld opened this issue Jun 25, 2016 · 6 comments

Comments

@kaaboeld
Copy link

Note: for support questions, please use one of these channels: https://github.com/angular/universal/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports.

  • I'm submitting a ...
  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

We have problem: adding SEO tags for any social networks without external HTML component.
https://gist.github.com/kaaboeld/851bc3190eec67f6723c6054751ee2dc

  • Please tell us about your environment:
  • Angular version: 2.0.0-RC-1
  • Browser: all
  • Language: TypeScript 1.8
  • OS: [all | Mac OS X | Windows | Linux ]
  • Platform: NodeJs
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
@rjokelai
Copy link

We solved this by creating the elements with the Renderer and injecting the Document too:

import { Component, AfterViewInit, Renderer, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';

@Component({ ... })
class AppComponent implements AfterViewInit {
  constructor(@Inject(DOCUMENT) private document: any, private renderer: Renderer) {}

  ngAfterViewInit(): void {
    const elem = this.renderer.createElement(this.document.head, 'meta');
    this.renderer.setProperty(elem, 'name', 'foo');
  }
}

@maxiar
Copy link

maxiar commented Aug 29, 2016

Hi @rjokelai / @kaaboeld I'm searching a SEO Angular 2 example fully working for all internet! :)
Please, can you share the code using your recomended fix?

Thanks in advanced..

@gjuchault
Copy link

@rjokelai I guess this is not the point of prerendering, as this will (correct me if I'm wrong) be added after rendering to the browser

@rjokelai
Copy link

No, this the way we got it actually working in the universal app. The meta tags are already sent with the prerendered html response. The point here is to use the DOCUMENT token and Renderer, which the universal library is aware of.

They actually use this kind of approach in the universal starter:

https://github.com/angular/universal-starter/blob/master/src/app/app.component.ts#L20

Our specific case is that we have a CMS-backed angular application. The meta information comes from the CMS and should be rendered for crawlers.

@jeffwhelpley
Copy link
Contributor

I am going to consolidate this issue with #309 where we are discussing creating universal services that will make it easy to change the meta tags.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants