【问题标题】:How to send default nextjs 404 not found error page from express?如何从快递发送默认的nextjs 404 not found错误页面?
【发布时间】:2019-05-11 19:43:41
【问题描述】:

当我的端点函数中发生异常时,我正在尝试从我的 express 端点访问默认的 nextjs 错误页面。我现在正在做的是:

try {
  //...
} catch(e) {
  res.status(404).send('Not Found !!!');
}

如何发送默认的 nextjs 404 页面而不是上面的操作?

【问题讨论】:

标签: node.js express next.js


【解决方案1】:

在下一个渲染应用程序之前,您无法关闭响应,因此您必须使用 app.render 并修改 res

【讨论】:

    【解决方案2】:

    你可以这样做

    try {
      //...
    } catch(e) {
     res.writeHead(301, { Location :"/"});
     res.end();
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多