首页 > 解决方案 > React Server.js 索引文件更改?

问题描述

server
  .disable('x-powered-by')
  .use(express.static(process.env.RAZZLE_PUBLIC_DIR))
  .get('/*', (req, res) => {
    const context = {}
    const markup = renderToStaticNodeStream(
      <StaticRouter location={req.url} context={context}>
        <App />
      </StaticRouter>
    );

    if (context.url) {
      // Somewhere a `<Redirect>` was rendered
      redirect(301, context.url);
    } else {
      res.status(200).send(
        `<!doctype html>
    <html lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta charset="utf-8" />
        <title>{meta.title}</title>
        <meta name="title" content={meta.title} />
        <meta name="description" content={meta.description} />
        <meta property="og:title" content={meta.title} />
        <meta property="og:image" content={meta.image} />
        <meta property="og:description" content={meta.description} />
        <meta property="og:url" content={meta.url} />

我正在尝试根据我的页面设置元标记以做出反应。当我从 server.js 渲染我的反应应用程序时。我现在可以根据页面更改元标记内容吗?

标签: javascriptreactjsexpressmeta-tags

解决方案


推荐阅读