Look up the first route pointing at the specified target (e.g. entrance/view-login
) and return its URL.
sails.getUrlFor(target);
Argument | Type | Details | |
---|---|---|---|
1 | target | The route target string; e.g. entrance/view-login or PageController.login |
Type:
'/login'
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>
- 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 itscode
property, it will be the stringE_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.