Edit Page

sails.getUrlFor()

Look up the first route pointing at the specified target (e.g. entrance/view-login) and return its URL.

sails.getUrlFor(target);

Usage

#
Argument Type Details
1 target String The route target string; e.g. entrance/view-login or PageController.login
Returns
#

Type: String

'/login'

Example

#

In a view...

<a href="<%= sails.getUrlFor('entrance/view-login') %>">Login</a>
<a href="<%= sails.getUrlFor('entrance/view-signup') %>">Signup</a>

Or, if you're using traditional controllers:

<a href="<%= sails.getUrlFor('PageController.login') %>">Login</a>
<a href="<%= sails.getUrlFor('PageController.signup') %>">Signup</a>

Notes

#
  • This function searches the Sails app's explicitly configured routes, sails.config.routes. Shadow routes bound by hooks (including blueprint routes) will not be matched.
  • If a matching target cannot be found, this function throws an E_NOT_FOUND error (i.e. if you catch the error and check its code property, it will be the string E_NOT_FOUND).
  • If more than one route matches the specified target, the first match is returned.
  • The HTTP method (or "verb") from the route address is ignored, if relevant.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference