【发布时间】:2021-10-30 01:52:57
【问题描述】:
我想从 nodejs 服务器提供一个 react 项目。我遇到了两种方法:
第一种方法是使用 express 为 req 生成的任何内容提供构建文件夹:
const express = require('express')
const app = express()
const path = require('path')
app.use(express.static(path.join(__dirname,'build')))
app.get('*',function(req,res){
res.sendFile(path.join(__dirname,'build','index.html'))
})
module.exports = app;
第二种方式是使用ReactDOM.hydrate 和ReactDOMServer.renderToString 为应用程序提供服务。它被描述为here。
从上述方法中获得良好 SEO 的最佳方法是什么?何时选择其中一种?
谢谢!!!
【问题讨论】:
标签: node.js reactjs seo server-side-rendering