View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

URL Slugs

A common use case for explicit routes is the design of slugs or vanity URLs. For example, consider the URL of a repository on Github, In Sails, we might define this route at the bottom of our config/routes.js file like so:

'get /:account/:repo': {
controller: 'RepoController',
action: 'show',
skipAssets: true

In your RepoController's show action, we'd use req.param('account') and req.param('repo') to look up the data for the appropriate repository, then pass it in to the appropriate view as locals. The skipAssets option ensures that the vanity route doesn't accidentally match any of our assets (e.g. /images/logo.png), so they are still accessible.

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-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.