首页 > 解决方案 > 带有动态标题和描述的 Whatsapp 共享

问题描述

我有一个使用 React 构建的网站,该网站托管在 www.url.com 域下,我在 index.html 上设置了以下元

<meta name="description" content="My description">
<meta property="og:title" content="My title" />
<meta property="og:url" content="https://www.url.com" />
<meta property="og:description" content="My description">
<meta property="og:image" content="https://www.myimage.com">
<meta property="og:type" content="website" />

我的网站中包含帖子,其中每个帖子都有其唯一的 URL(如 www.url.com/post/thispost)、标题、描述和图像。我使用 ShareThis reactjs 插件(https://github.com/sharethis-github/sharethis-reactjs)为每个帖子创建共享按钮,并具有以下设置

<InlineShareButtons
    config={{
    alignment: 'center',  // alignment of buttons (left, center, right)
    color: 'social',      // set the color of buttons (social, white)
    enabled: true,        // show/hide buttons (true, false)
    font_size: 14,        // font size for the buttons
    labels: 'cta',        // button labels (cta, counts, null)
    language: 'en',       // which language to use (see LANGUAGES)
    networks: [           // which networks to include (see SHARING NETWORKS)
                'whatsapp',
                'facebook'
              ],
    padding: 12,          // padding within buttons (INTEGER)
    radius: 4,            // the corner radius on each button (INTEGER)
    show_total: false,
    size: 40,             // the size of each button (INTEGER)
    // OPTIONAL PARAMETERS
    url: window.location.href, // (defaults to current url)
    description: {description},       // (defaults to og:description or twitter:description)
    title: {title},            // (defaults to og:title or twitter:title)

 }}
/>

其中 description 和 title 是每个帖子的内容和标题。由于每个帖子都是一个弹出窗口,并且标题和描述只有在打开弹出窗口时才可用,所以我设计它只在弹出窗口打开时初始化 InlineShareButtons。

但这里的问题是,当我分享帖子时,它没有以我想要的方式显示描述和标题。相反,每当我尝试分享每个帖子时,它都会显示 index.html 上元标记的描述和标题。

有没有办法让我分享任何帖子时,它会使用帖子上的标题和描述?

标签: reactjssharethis

解决方案


推荐阅读