React meta tags not working for Facebook

别说谁变了你拦得住时间么 提交于 2019-12-13 07:29:17

问题


I have clone the app https://github.com/alanbsmith/react-node-example and try to use the react-helmet. By inspecting the browser I can see the meta tags values are present but when I post the URL on Facebook and try to see the meta tag status here, https://developers.facebook.com/tools/debug/sharing/ It says The properties should be passed. Please anyone can suggest whats going wrong here.

Please find my component code,

import '../assets/stylesheets/base.scss';
import React, { Component } from 'react';
import Helmet from "react-helmet";

class App extends Component {
  render() {
    return(
        <div className="application">
            <Helmet
            htmlAttributes={{"lang": "en", "amp": undefined}} // amp takes no value
            title="My Title"
            titleTemplate="React Helmet - %s"
            defaultTitle="React Helmet Title"
            base={{"target": "_blank", "href": "http://myappname.herokuapp.com/"}}
            meta={[
                {"name": "description", "content": "Helmet application"},
                {"property": "fb:app_id", "content": "myfbid"},
                {"property": "og:title", "content": "My application title goes here."},
                {"property": "og:type", "content": "website"},
                {"property": "og:url", "content": "http://myappname.com/"},
                {"property": "og:image", "content": "https://imagename.png"},
                {"property": "og:description", "content": "Application description"},
                {"property": "og:site_name", "content": "MyAppname.com"},

            ]}
          />
          <h1>Welcome to the React helmet App, {this.props.name}!</h1>
        </div>  
    )
  }
};
export default App;

回答1:


That's because Facebook's Page scrapper doesn't execute javascript (unlike Google's Page Scrapper, I believe). This means you need to pre-process and add the meta-tags on the server side.

In Chrome you can see exactly what your server is returning by using view-source

view-source:http://example.com


来源:https://stackoverflow.com/questions/40868686/react-meta-tags-not-working-for-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!