Sails.js non-static routing urls

非 Y 不嫁゛ 提交于 2019-12-14 03:57:15

问题


So I was working with this Sails.js flash message for user registration but then I got into a new issue. So basically I am using the following in the user controller to render non-static content of the user/register.js file to client.

'register': function(req, res){
    res.view();
},

This however means that the address to access the registration page will be http://localhost/user/register. Is it possible to change this url to work with http://localhost/register without webpage redirects (possibly from the above code itself)? This I believe can be handled using custom redirects Custom Routes. But using redirects could be ugly at times?


回答1:


You linked to right documentation, but didn't look in the right section. You want to use the controller/action custom route syntax to route /register to the UserController.register action:

"/register": "UserController.register"

or

"/register": {controller: 'user', action: 'register'}

in your config/routes.js will do what you want.

To disable the default /user/register route, you can either 1) set actions to false in config/blueprints.js (this will turn off all default controller/action routing), or explicitly disable the route in config/routes.js:

"/user/register": {response: 'notFound'}



回答2:


OP's solution to the case in the comment.

[I was not able to solve "/user/register": {response: 'notFound'} by sgress454 proposal]. However, turning actions to false in config/blueprints.js did the trick.

Sails version < 0.10.x because the other answer solution should work here.



来源:https://stackoverflow.com/questions/25356827/sails-js-non-static-routing-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!