繁体   English   中英

在 Sailsjs 中未找到未找到的路线

[英]Not found route not found in Sailsjs

根据Sailsjs 文档,可以在路由文件中添加一个使用如下语法的响应:

module.exports.routes = {
    '/foo': {response: 'notFound'}
};

这将在/response目录中搜索notFound.js文件,我在那里。

因此,在我的routes.js文件中,我将其添加为其他路由的末尾以捕获未找到的路由,它是这样的:

module.exports.routes = {
    'get  /myroute/:myPara/': 'MyController.getAll',
    'get  /myroute/:myPara/': 'MyController.getOne',
    'post /myroute/:myPara/': 'MyController.create',
    '/*' : {response: 'notFound'}
};

我意识到永远找不到最后一条路线,我也尝试删除斜线(执行'*' ),但没有任何效果。

我错过了什么吗? 谢谢!

Sails 已经处理了 404 notFound : 这里

Sails 调用 res.notFound() 并且您可以覆盖默认的 notFound():

res.notFound() (与其他用户空间响应方法一样)可以被覆盖或修改。 它运行 /responses/notFound.js 中定义的响应方法,该方法自动捆绑在新生成的 Sails 应用程序中。 如果您的应用程序中不存在 notFound.js 响应方法,Sails 将隐式使用默认行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM