Inactive Sails.js Routing URLs

So, I worked with this flag message Sails.js to register the user , but then I got into a new problem. Therefore, I mainly use the following in the user controller to display the non-static contents of the user/register.js file to the client.

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

This means that the address for accessing the registration page will be http://localhost/user/register . Is it possible to change this URL to work with http://localhost/register without redirecting the web page (possibly from the code itself)? This, I believe, can be handled with custom redirects. Custom routes . But can using redirects be ugly at times?

+2
source share
2 answers

You contacted the relevant documentation, but did not look in the right section. You want to use the controller / custom route action to route / register to the UserController.register action:

 "/register": "UserController.register" 

or

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

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

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

 "/user/register": {response: 'notFound'} 
+3
source

OP solution for the case in the comment.

[I could not resolve "/user/register": {response: 'notFound'} with the sgress454 clause]. However, turning actions to false in config/blueprints.js did the trick.

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

0
source

Source: https://habr.com/ru/post/1200537/


All Articles