6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SailsのRoutes定義方法まとめ

Last updated at Posted at 2014-05-01

Sailsバージョン:0.9.16

config/routes.jsでroutesを定義する際、やり方がいろいろあったのでちょっとまとめてみる。

config/routes.js
// /users => {method: get, controller: users, action: index} をいろんな方法で定義
module.exports.routes = {
  'get /users': {
    controller: 'users',
    action: 'index'
  },
  'get /users': {
    controller: 'UsersController',
    action: 'index'
  },
  '/users': { // メソッド指定を省略すると自動で"get"メソッドが設定される
    controller: 'users',
    action: 'index'
  },
  'get /users': 'users.index',
  'get /users': 'UsersController.index',
  'get /users': 'UsersController', // アクション指定を省略すると自動で"index"がアクションに設定される,
  'get /user*': { // wildcardで指定
    controller: 'users',
    action: 'index'
  }
};
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?