我有 SPA sails 应用程序。我的 SPA 应用程序中的所有路线,首先进入欢迎操作 Controller 。
'/*' :{
controller : 'Web/welcomeController',
skipAssets : true
}
所有其他路由都使用类似 api 的 ajax 请求。该路由“/*”仅用于第一个渲染页面。所有其他渲染都提供 angularjs。在那里,其中一个路由有带点的 get 参数。
http://localhost:1337/search?lat=40.714545&long=-74.007112
我收到 404 错误。这一切都是由于参数skipAsset,它忽略了带有内容点的url。
我需要 Controller 还跳过 Assets 资源,如图像、js 等。但正确处理带有内容点 /?lat=40.714545&long=-74.007112
最佳答案
skipAssets
可能应该修复为忽略查询字符串。但与此同时,您可以使用 skipRegex
代替 skipAssets
。来自 Sails.js docs on custom routes :
If skipping every URL containing a dot is too permissive, or you need a route's handler to be skipped based on different criteria entirely, you can use skipRegex. This option allows you to specify a regular expression or array of regular expressions to match the request URL against; if any of the matches are successful, the handler is skipped. Note that unlike the syntax for binding a handler with a regular expression, skipRegex expects actual RegExp objects, not strings.
所以类似:
'/*' :{
controller : 'Web/welcomeController',
skipRegex : /^[^?]+\./
}
可能就足够了。
关于node.js - Sails 在 get-parameters 上给出 404 ".",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25704336/