如何在sails.js中重写URL

时间:2015-08-31 14:17:01

标签: sails.js

任何人都可以帮助我,我想重写http://www.example.in/search?city=' xyz' 至 http://www.example.in/city/xyz 在sails.js

1 个答案:

答案 0 :(得分:0)

查看文档的url slug部分。

你可以像这样创建一条路线:

// config/routes.js
module.exports.routes = {
  // The simple route you use to access to the search controller for now
  'get /search': 'SearchController.index'

  // The "rewritten" route that calls the same controller
  // processing ":city" as if it was part of the query string
  'get /city/:city': 'SearchController.index'
}

然后,http://www.example.in/search?city=xyzhttp://www.example.in/city/xyz将具有相同的结果,就像您使用网址重写Nginx或Apache一样。