【问题标题】:is there a way to share react page on Facebook and pass an image?is there a way to share react page on Facebook and pass an image?
【发布时间】:2022-12-26 19:20:53
【问题描述】:

am trying to make my react page shareable on Facebook and Twitter. I tried everything I could, I have been googling all day, but I cant find the answer.

 <FacebookShareButton url={window.location.href} title={exactNews.text ?exactNews.title : ""}> 
                         <FaFacebookF/>
                       </FacebookShareButton>

any tips?

【问题讨论】:

    标签: reactjs facebook twitter react-share


    【解决方案1】:

    There is no way to pass an image to the share options anymore, the only way to add an image to a shared URL is by using the og:image tag in the source. Be aware that Facebook ignores JavaScript, so the og:image tag must be in the original source and not dynamically added via JavaScript. Facebook then automatically uses the image specified in the og:image tag.

    More information: https://ogp.me/

    【讨论】:

    • yeah, I have been trying to do that with dynamical method but I guess there is no way. how can I make it work? for now am trying to make it work using react-helmet-async, but I dont think that it will work. I cant just add it statically, because am fetching images from api. any tips on how to make it work?
    • you really have to generate the og tags serverside, there is no way around that...
    • willl pre-render help my case?
    • i dont know your code, but as long as the source includes the og tags without any javascript, it is fine
    猜你喜欢
    • 2022-12-26
    • 2022-12-01
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-26
    • 2022-12-28
    • 2022-07-14
    相关资源
    最近更新 更多