Home文件
import React from 'react';
const Home = () => {
return <div>这是一个演示地址</div>
}
export default Home;
import express from 'express';
import Home from './containers/Home';
import React from 'react';
import {renderToString} from 'react-dom/server';
const port = 3000;
const app = express();
const content = renderToString( < Home / >
)
app.get('/', (req, res) => {
res.send(`
<html>
<title>SSR</title>
<body>
${content}
</body>
</html>
`);
});
app.listen(port, () => {
console.log(`访问地址是 http://localhost:${port}`)
});