gpt4 book ai didi

ReactJS header tags in different pages(不同页面中的ReactJS Header标签)

转载 作者:bug小助手 更新时间:2023-10-25 12:26:33 26 4
gpt4 key购买 nike



I am pretty new to react, and I have several pages I want to have different header content in. For instance, my index.js page has another title than my contact.js, and also meta information as well.

我是一个非常新的反应,我有几个页面,我想有不同的标题内容。例如,我的index.js页面有另一个标题,而不是我的联系人.js,还有元信息。



I thought I solved this problem by installing react-meta-tags, where I have put my content like this:

我以为我通过安装reaction-meta-tag解决了这个问题,我把我的内容放在这样的地方:



class Index extends React.Component {
render() {
return(
<div>
<MetaTags>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="copyright" content="" />
<meta name="robots" content="index,follow" />
<meta name="author" content="" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</MetaTags>
<Header/>
<Experience/>
<Projects/>
<Contact/>
<Footer/>
</div>
);
}
}


However, this does not seem to work, even though a numerous of Google searches, people claimed that the Google bots were smart enough to catch this. You see, when I search up my own page on Google, it just displays my website URL (typically for websites with no title), and it also tells me that my website is not mobile friendly, which it is. And when I click the link, or go to my page directly - it shows up perfectly responsive.

然而,这似乎并不管用,尽管人们在谷歌上进行了大量搜索,但人们声称谷歌机器人足够聪明,能够捕捉到这一点。你看,当我在谷歌上搜索我自己的页面时,它只显示我的网站URL(通常是没有标题的网站),它还告诉我,我的网站对移动设备不友好,但事实并非如此。当我点击链接,或者直接转到我的页面时,它会显示出完美的响应。



If I put this code in my index.html file, it all seems to work perfectly. The only problem I have then, is that I will only have one title, and the same keywords on all of my pages. How can I fix this?

如果我把这段代码放在我的index.html文件中,它似乎都能完美地工作。我唯一的问题是,我将只有一个标题,在我的所有页面上都有相同的关键字。我怎么才能解决这个问题呢?



I'm not sure, but I am pretty certain that this will hurt my SEO. Even though I have everything working, it doesn't really matter as long as Google doesn't recognize important content like the meta tags I have listed.

我不确定,但我相当肯定,这将损害我的搜索引擎优化。即使我一切正常,只要谷歌不识别像我列出的元标签这样的重要内容,那就没什么关系了。


更多回答

'react-document-meta' seems like a better library to add meta tags. Check it out.

‘Reaction-Document-Meta’似乎是一个更好的添加元标签的库。看看这个。

@raksheetbhat I checked that out, but I couldn't seem to use it properly. So with some Google searches, I tried another two plugins - one of them called react helmet. It works perfectly when I visit the website, but when I do a SEO check on my website, it still says that title and meta tags are missing. Could this be due to the fact that Helmet is server-side, and therefore gets rendered after the static HTML content and therefore has a 'delay' and that might be why Google (?) and other SEO checkers won't regognize it?

@raksheetbhat我检查了一下,但我似乎不能正确使用它。所以在谷歌上搜索了一下,我又试了两个插件--其中一个叫react helmet。当我访问网站时,它工作得很好,但是当我在我的网站上做SEO检查时,它仍然说标题和Meta标签丢失了。这可能是由于Helmet是服务器端的,因此在静态HTML内容之后呈现,因此有一个“延迟”,这可能就是为什么Google(?)和其他SEO检查员不会regognize它?

Yes, you're right as mentioned here: brombone.com/what-is-the-javascript-seo-problem, which says, "These frameworks are using the browser to build the actual content of the page. When Google crawls your site, it just reads the raw pages. It doesn't open them in a browser and it doesn't run the javascript. So, it doesn't see the content, it just sees an empty page."

是的,正如这里提到的那样:brombone.com/what-is-the-javascript-seo-problem,说,“这些框架使用浏览器构建页面的实际内容。当谷歌抓取你的网站时,它只读取原始页面。它不会在浏览器中打开它们,也不会运行Java脚本。所以,它看不到内容,它只看到一个空页面。”

@raksheetbhat I see. But there has to be some kind of fix for this? I mean, reactJS isn't one of the most popular JavaScript frameworks for nothing?

@raksheetbhat我看到了。但一定有什么办法解决这个问题吧?我的意思是,reactJS不是最流行的JavaScript框架之一吗?

You're right. I guess one way to go would be to try a few more components till one of them works :\. I wish I had a better answer. Here's a discussion on the same question: discuss.reactjs.org/t/…, which suggests 'react-document.title'. Hope this one works for you.

你是对的。我想一种方法是再尝试几个组件,直到其中一个组件起作用:我希望我能有一个更好的答案。这里有一个关于同一问题的讨论:exposess.reactjs.org/t/…,这建议使用“Reaction-Document.Title”。希望这本书对你有用。

优秀答案推荐

React helmet is in my experience the better choice.
When it comes to SEO you should get all the data that crawlers care about to be rendered serverside. What you could do to speed up the troubleshooting is to view the page source of you page instead of the markup after all client-javascript has run. This way you can see your pages as the crawlers do and determine if the markup is correct.
Be aware of that search engines do not catch changes in your pages instantly, these pages need to be crawled and indexed before new changes are shown (this can take some time).

在我的经验中,Reaction头盔是更好的选择。当涉及到SEO时,你应该获得爬虫程序关心的所有数据,以便在服务器端呈现。为了加快故障排除速度,您可以在运行完所有的客户端脚本之后查看页面的页面源代码,而不是标记。这样,您就可以像爬行器一样查看页面,并确定标记是否正确。请注意,搜索引擎不会立即捕获页面中的更改,需要在显示新更改之前对这些页面进行爬行和索引(这可能需要一些时间)。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com