# Route and resource

**URL:** <https://discuss.emberjs.com/t/route-and-resource/6224>\
**Category:** Uncategorized\
**Created:** [September 8, 2014, 8:44am UTC](https://discuss.emberjs.com/t/route-and-resource/6224 "2014-09-08T08:44:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Briga](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Briga](https://discuss.emberjs.com/u/Briga)\
**Post date:** [September 8, 2014, 8:44am UTC](https://discuss.emberjs.com/t/route-and-resource/6224/1 "2014-09-08T08:44:52Z")

</div>

Now that you can nest routes, which is the main difference between routes and resources? I used to think to resources as routes containers, but now I’m a bit confused.

Regards, Gabri

---

<div class="post-metadata">

**Author:** ![gerrit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gerrit/32/9140_2.png) [@gerrit](https://discuss.emberjs.com/u/gerrit)\
**Post date:** [September 8, 2014, 10:19am UTC](https://discuss.emberjs.com/t/route-and-resource/6224/2 "2014-09-08T10:19:40Z")

</div>

I think in general, a resource is the representation of your model and a route is an action or a verb… So in a login Route you do something… you log in. In the posts resource-route, you have records…

Thats the difference I see

/api/posts/ its a resource. you index alot of records.

/api/posts/new there is additionally an action route to the resource route, because you do something… You create a new record.

So it would be like

/api/model/action == /api/comments/new

---

<div class="post-metadata">

**Author:** ![rwjblue](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rwjblue/32/9411_2.png) [@rwjblue](https://discuss.emberjs.com/u/rwjblue)\
**Post date:** [September 8, 2014, 11:50am UTC](https://discuss.emberjs.com/t/route-and-resource/6224/3 "2014-09-08T11:50:30Z")

</div>

The only real difference as of 1.7.0 is that resources reset the namespace. A few examples:

### Using `this.resource`

```javascript
Router.map(function() {
  this.resource('post', { path: '/post/:post_id' }, function() {
    this.route('edit');
    this.resource('comments', function() {
      this.route('new');
    });
  });
});

```

Will result in looking for the following files (assuming ember-cli layout):

```auto
// posts
app/route/posts.js
app/route/posts/index.js
app/templates/posts.hbs
app/templates/posts/index.hbs

// edit
app/route/posts/edit.js
app/templates/posts/edit.hbs

// comments
app/route/comments.js
app/route/comments/index.js
app/templates/comments.hbs
app/templates/comments/index.hbs

// new
app/route/comments/new.js
app/templates/comments/new.hbs

```

Note that the `comments` resource is **not** nested under `posts` (this is what I mean when I say the namespace is “reset”).

### Using `this.route`

```javascript
Router.map(function() {
  this.route('post', { path: '/post/:post_id' }, function() {
    this.route('edit');
    this.route('comments', function() {
      this.route('new');
    });
  });
});

```

Will result in looking for the following files (assuming ember-cli layout):

```auto
// posts
app/route/posts.js
app/route/posts/index.js
app/templates/posts.hbs
app/templates/posts/index.hbs

// edit
app/route/posts/edit.js
app/templates/posts/edit.hbs

// comments
app/route/posts/comments.js
app/route/posts/comments/index.js
app/templates/posts/comments.hbs
app/templates/posts/comments/index.hbs

// new
app/route/posts/comments/new.js
app/templates/posts/comments/new.hbs

```

Note that the `comments` route is nested under `posts`.

---

<div class="post-metadata">

**Author:** ![joseph\_dillon\_522](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/joseph_dillon_522/32/9348_2.png) [@joseph\_dillon\_522](https://discuss.emberjs.com/u/joseph_dillon_522)\
**Post date:** [September 8, 2014, 2:11pm UTC](https://discuss.emberjs.com/t/route-and-resource/6224/4 "2014-09-08T14:11:21Z")

</div>

> [@rwjblue](#):
>
> Note that the comments route is nested under posts.

Good breakdown. Is there a real reason to use one or the other, or is it mostly organizational preference?

---

<div class="post-metadata">

**Author:** ![rwjblue](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rwjblue/32/9411_2.png) [@rwjblue](https://discuss.emberjs.com/u/rwjblue)\
**Post date:** [September 8, 2014, 2:24pm UTC](https://discuss.emberjs.com/t/route-and-resource/6224/5 "2014-09-08T14:24:39Z")

</div>

> [@joseph\_dillon\_522](#):
>
> Is there a real reason to use one or the other, or is it mostly organizational preference?

I believe over the long term, `this.resource` will be deprecated, but it will obviously be supported for quite a while.
