如何使用Iron Router返回404 [英] How to return 404 using Iron Router

查看:67
本文介绍了如何使用Iron Router返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我遇到使用IR的Meteor应用程序中不存在的路由时,我收到一个200响应,该响应带有HTML(在浏览器上呈现时)在控制台上显示js错误的HTML,表示No route found for path: "/aRoute"

When I hit a route that doesn't exist on my Meteor app that uses IR, I get a 200 response with an HTML that (when rendered on a browser) displays a js error on console saying that No route found for path: "/aRoute".

如何使它返回404?

推荐答案

目前似乎没有正确(甚至无法工作?)的方法来处理真正的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 );
  }
});

这篇关于如何使用Iron Router返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆