如何重写Url并将其路由到Sailsjs中的不同控制器操作?

时间:2015-09-11 06:13:48

标签: javascript node.js sails.js

正如我在标题中所写,我想重写URL并将其路由到不同的控制器动作。

原始网址:/category1/city/locality

重写网址:/city/locality

处理程序:Controller1.action

原始网址:/category2/city/product

重写网址:/city/product

处理程序:Controller2.action

原始网址:/category3/city/group

重写网址:/city/group

处理程序:Controller3.action

module.exports.routes = {
  // The original url and rewritten url route to the search controller
  'get /category1/:city/:locality': {'/:city/:locality', localityController.action},
  // The original url and rewritten url route to Product controller
  'get /category2/:city/:product': {'/:city/:product', productController.action},
  // The original url and rewritten url route to group controller
  'get /category3/:city/:group': {'/:city/:group', groupController.action}
 }

欢迎任何建议。谢谢。

0 个答案:

没有答案