且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Iron Router返回404

更新时间:2023-02-13 22:59:10

目前似乎没有正确(甚至无法工作?)的方法来处理真正的404.例如,请参见此问题: https://github.com/EventedMind/iron-router/issues/1055

There don't seem to be a correct (or even working?) way of handling real 404's right now. See this issue for example: https://github.com/EventedMind/iron-router/issues/1055

即使您尝试了应该的工作方式,您仍然会得到200状态代码.像下面这样的代码应该可以工作:

Even when you try ways which should work, you'll still end up with a 200 status code. Like this code below which should work:

this.route( 'pageNotFound', {
  path: '/(.*)',
  where: 'server',
  action: function() {
    this.response.writeHead(404);
    this.response.end( html );
  }
});