使用 php yii v1.1 反应动态元标签

React dynamic meta tags with php yii v1.1

我正在为电影目录网站构建一个带有 reactjs 的新前端,其中 PHP (Yii 1.1) 被用作后端技术。 元标记的所有数据都存储在数据库中,我想知道我应该使用 Yii 1 来构建社交网络可以发现的动态元标记。

在前端您可以使用 react-document-meta

从 api 获取元对象并将该值传递给从 react-document-meta

导入的 <DocumentMeta />
const meta = {
    title: 'Some Meta Title',
    description: 'I am a description, and I can create multiple tags',
    canonical: 'http://example.com/path/to/page',
    meta: {
        charset: 'utf-8',
        name: {
            keywords: 'react,meta,document,html,tags'
        }
    }
}

在渲染方法中写入:

    <DocumentMeta {...meta} />

Note that social networks can't read this meta tags and if you do it with javascript it will be unaccessible for them. Meta tags should be loaded in html code from backend to be accessible for social networks

在后端用 php 编写元标记的解决方案是用 php 加载 html 或使用 SSR(服务器端渲染)。它们都会导致您的网站刷新。

希望对您有所帮助