# Route vs Controller

**URL:** <https://discuss.emberjs.com/t/route-vs-controller/16026>\
**Category:** Uncategorized\
**Created:** [January 16, 2019, 8:01am UTC](https://discuss.emberjs.com/t/route-vs-controller/16026 "2019-01-16T08:01:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimParsons](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JimParsons](https://discuss.emberjs.com/u/JimParsons)\
**Post date:** [January 16, 2019, 8:01am UTC](https://discuss.emberjs.com/t/route-vs-controller/16026/1 "2019-01-16T08:01:35Z")

</div>

If I pass the data from the Route’s model as well as the controller, which of them will be used? Say for example, I pass value=A from route and value=B from the controller and when the value is accessed which one will be printed?

Also, why does it happen so ?

---

<div class="post-metadata">

**Author:** ![francesconovy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/francesconovy/32/9607_2.png) [@francesconovy](https://discuss.emberjs.com/u/francesconovy)\
**Post date:** [January 16, 2019, 4:21pm UTC](https://discuss.emberjs.com/t/route-vs-controller/16026/2 "2019-01-16T16:21:18Z")

</div>

As far as I know, what is actually happening when you enter a route is:

1. The route `model()` hook is called
2. Once that resolves, the route `setupController(controller, model)` hook is called, which by default basically does `set(controller, 'model', model)`

So I guess the route will overwrite whatever you set as `model` on the controller once the user navigates there. Also see [Route - 3.7 - Ember API Documentation](https://emberjs.com/api/ember/3.7/classes/Route/methods/setupController?anchor=setupController) for details on that

---

<div class="post-metadata">

**Author:** ![JimParsons](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JimParsons](https://discuss.emberjs.com/u/JimParsons)\
**Post date:** [January 17, 2019, 1:45pm UTC](https://discuss.emberjs.com/t/route-vs-controller/16026/3 "2019-01-17T13:45:46Z")

</div>

Thanks for your reply ! So as you said, the setupController hook will be called after the model hook. In the setup controller method, I’m passing the model for that particular controller. How to access the model that is passed from the route in the controller? Which hook to use ?

---

<div class="post-metadata">

**Author:** ![francesconovy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/francesconovy/32/9607_2.png) [@francesconovy](https://discuss.emberjs.com/u/francesconovy)\
**Post date:** [January 21, 2019, 10:36am UTC](https://discuss.emberjs.com/t/route-vs-controller/16026/4 "2019-01-21T10:36:41Z")

</div>

In the controller you can just access it via `this.model`. There is no hook on the controller for that, any setup you need to do based on this can/should be done on the route. E.g. if you want the `setupMyModel()` method on the controller to be run, you could have a `setupController` method on the route like this:

```nohighlight
setupController(controller, model) {
  this._super(...arguments);
  controller.setupMyModel();
}

```

---

<div class="post-metadata">

**Author:** ![JimParsons](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@JimParsons](https://discuss.emberjs.com/u/JimParsons)\
**Post date:** [January 22, 2019, 5:44am UTC](https://discuss.emberjs.com/t/route-vs-controller/16026/5 "2019-01-22T05:44:23Z")

</div>

@francesconovy Thank you. Will try that ! 🙂

---

<div class="post-metadata">

**Author:** ![zoltan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/zoltan/32/16699_2.png) [@zoltan](https://discuss.emberjs.com/u/zoltan)\
**Post date:** [January 22, 2019, 6:43pm UTC](https://discuss.emberjs.com/t/route-vs-controller/16026/6 "2019-01-22T18:43:41Z")

</div>

If you interested, there is a whole free tutorial which teach you the main concept behind Ember.js. Up to date: [https://yoember.com](https://yoember.com)
