小编Kir*_*ill的帖子

Next JS 自定义服务器 app.render 不将查询传递给组件

我试图通过userDataapp.render但是虽然服务器端渲染 router.query是空的,但我已经通过了userData!这是 NextJS 的错误,还是我做错了什么?

应用程序.js:

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer((req, res) => {

    const parsedUrl = parse(req.url, true)
    const { pathname, query } = parsedUrl

    if (pathname === '/index') {
      app.render(req, res, '/index', {
        userData: {
          id: 1,
          name: 'admin'
        } …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs next.js

5
推荐指数
1
解决办法
2931
查看次数

标签 统计

next.js ×1

node.js ×1

reactjs ×1