Redirect the requesting user-agent to the given absolute or relative url.
||A URL expression (see below for complete specification).
Sails/Express/Koa/Connect support a few forms of redirection, first being a fully qualified URI for redirecting to a different domain:
--> Pathname relative redirects are also possible. If you were on http://example.com/admin/post/new, the following redirect would land you at http//example.com/admin/post:
The final special-case is a back redirect, which allows you to redirect a request back where it came from using the "Referer" (or "Referrer") header (if omitted, redirects to `/` by default)
return res.redirect('back'); ```
- This method is terminal, meaning it is generally the last line of code your app should run for a given request (hence the advisory usage of
returnthroughout these docs).
- When your app calls
res.redirect(), Sails sends a response with status code 302. This instructs the user-agent to send a new request to the indicated URL. There is no way to force a user-agent to follow redirects, but most clients play nicely.
- In general, you should not need to use
res.redirect()if a request "wants JSON" (i.e.
- If a request originated from a Socket.io client, it always "wants JSON". If you do call
res.redirect(http://sailsjs.org/documentation/reference/res/res.redirect.html)for a socket request, Sails reroutes the request internally on the server, effectively "forcing" the redirect to take place (i.e. instead of sending a 302 status code, the server simply creates a new request to the redirect URL).
- As a result, redirects to external domains are not supported for socket requests (although this is technically possible by proxying).
- This behavior may change to more closely reflect HTTP in future versions of Sails.