Skip to content

Instantly share code, notes, and snippets.

@ef4
Last active October 19, 2016 00:08
Show Gist options
  • Save ef4/def026cf7b03a2e1e183 to your computer and use it in GitHub Desktop.
Save ef4/def026cf7b03a2e1e183 to your computer and use it in GitHub Desktop.
route vs resource in Ember route map
// "route" and "resource" are almost interchangeable. Both of these work fine:
this.route('people', function(){
this.route('person', {path: '/:person_id'})
})
this.route('people', function(){
this.resource('person', {path: '/:person_id'})
})
// And they both establish the same URLs, namely
// - /people
// - /people/:person_id
// The only difference is how their Routes get named. The first example above will use:
// app/routes/people.js
// app/routes/people/person.js
// whereas the second one will use:
// app/routes/people.js
// app/routes/person.js
// For new apps using ember-cli, I would recommend using 'route' for everything. It's
// simple and makes your file hierarchy on disk match your URL hierarchy in router.js.
// 'resource' exists mostly for historical reasons, but as the API has evolved it is not
// so important anymore and it will be logical if it gets deprecated eventually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment