[英]Using react-snap for SEO
I'm using react snap for SEO.我正在为 SEO 使用 react snap。
Here's what I did.这就是我所做的。
I added the following to index.js in my react application我在我的反应应用程序中将以下内容添加到 index.js
import React from 'react';
import { hydrate, render } from "react-dom";
const rootElement = document.getElementById("root");
if (rootElement.hasChildNodes()) {
hydrate(<App />, rootElement);
} else {
render(<App />, rootElement);
}
Then I added the following to package.json然后我将以下内容添加到 package.json
"postbuild": "react-snap"
When I run npm run build
, and do View Source on the pages, I don't see the real time meta description and title that I need for the page.当我运行npm run build
并在页面上查看源代码时,我看不到页面所需的实时元描述和标题。
What am I doing wrong?我究竟做错了什么?
Here's how I set the meta tags.这是我设置元标记的方法。
In BookDetail.jsx在 BookDetail.jsx 中
import {Helmet} from "react-helmet";
<Helmet>
<meta charSet="utf-8" />
<title>{this.state.book.title} by {this.state.book.author} | Sumizeit</title>
<meta name="description" content={this.state.book.desc}/>
</Helmet>
不要使用 react-snap 只需更改为 next.js(react-snap 有很多问题:受保护路由上的刷新错误,构建时间不开玩笑,内联 css)...顺便说一下,您的代码没有任何问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.