简体   繁体   English

社交媒体分享未通过 react-helmet 或 react-meta-tags 在 react-app 中获取元标签

[英]Social media share not picking up meta tags in react-app via react-helmet or react-meta-tags

I have an application built with React.js and I want to customize the look of the URL that is shared on social media using HTML meta tags.我有一个使用 React.js 构建的应用程序,我想自定义 URL 的外观,它使用 HTML 元标记在社交媒体上共享。

I have tried to use react-helmet and react-meta-tags that are used for adding meta tags, but they didn't help.我尝试使用用于添加元标记的 react-helmet 和 react-meta-tags,但它们没有帮助。

Is the only solution to this problem to use server-side rendering or there is a way to handle it from front-end only?这个问题的唯一解决方案是使用服务器端渲染还是有办法只从前端处理它?

first install: npm install react-helmet --save第一次安装:npm install react-helmet --save

and then Add meta tag: like!然后添加元标记:like!

 import React from 'react' import { Helmet } from "react-helmet"; class App extends React.Component { render () { return ( <div> <Helmet> <title>App Title</title> <link rel="canonical" href="https://malikgabroun.com" /> </Helmet> </div> ); } };

EXAMPLE:例子:

 import { Helmet } from 'react-helmet'; import React from 'react'; const Seo = ({ title, description, pathSlug, keywords }) => { const url = `https://malikgabroun.com/${pathSlug}` return ( <Helmet htmlAttributes={{ lang: 'en' }} title={title} meta={[ { name: 'description', content: description, }, { name: 'keywords', content: keywords.join(), }, ]} links={[ { rel: 'canonical', href: url, }, ]} /> ); } export default Seo;

For more details go for this link and read it.有关此链接的更多详细信息 go 并阅读。 https://levelup.gitconnected.com/how-to-add-metadata-in-react-using-react-helmet-6dd316d146c2 https://levelup.gitconnected.com/how-to-add-metadata-in-react-using-react-helmet-6dd316d146c2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM