Angular4社交媒体Facebook分享页面详情

时间:2018-01-24 00:13:38

标签: javascript html angular facebook nginx

渔获物在哪里:

  1. Nginx作为服务Angular 4 app
  2. Angular 4元标记仅从FB请求路径上的基本href读取
  3. 角度路径可以是(示例): https://domain.pa/book/12/Book名称

    Nginx设置简单:

    root /home/web/dist;
    index index.html index.htm;
    location / {
    expires -1;
    try_files $uri $uri/ /index.html;
    autoindex on;
    }
    

    在Angular App中,我编写的服务适用于:

    import { Meta } from '@angular/platform-browser';
    

    在每个页面上,我都会更新Facebook的元标记:

    this.meta.updateTag({ property: 'og:type', content: 'article' });
    this.meta.updateTag({ property: 'og:site_name', content: 'AdriaOffer' });
    this.meta.updateTag({ property: 'og:title', content: config.title });
    this.meta.updateTag({ property: 'og:description', content: config.description });
    this.meta.updateTag({ property: 'og:image', content: config.image });
    this.meta.updateTag({ property: 'og:url', content: config.slug });
    

    当我更改页面元标记时,它运行良好。真的不知道在哪里看,以及如何为Facebook Share插件提供元数据。也许你有一些类似的搜索引擎优化单页网页应用程序。

2 个答案:

答案 0 :(得分:1)

机器人未检测到您的项目,因为它是 PreRender 。如果您希望靴子看到您的内容,您应该执行服务器端渲染(SSR)。

您应该使用Angular Universal或(我的推荐)Rendertron

答案 1 :(得分:0)

我一直在使用角度+预渲染的组合,因为有角度的第1版,这一直是我的推荐,直到我给角度普遍的新机会。

我第一次尝试设置角度通用时,文档非常困惑,但知道有一个官方文档

https://angular.io/guide/universal

相关问题