# Preloading data before routing

**URL:** <https://discuss.emberjs.com/t/preloading-data-before-routing/1014>\
**Category:** Uncategorized\
**Created:** [April 17, 2013, 6:44pm UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014 "2013-04-17T18:44:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![studio816](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/studio816/32/4122_2.png) [@studio816](https://discuss.emberjs.com/u/studio816)\
**Post date:** [April 17, 2013, 6:44pm UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/1 "2013-04-17T18:44:56Z")

</div>

What is the recommended way of pre-loading some data that’s used application-wide before any routing takes place?

For example, what’s the best way to ensure that user settings/preferences are loaded before navigation bar is rendered?

---

<div class="post-metadata">

**Author:** ![studio816](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/studio816/32/4122_2.png) [@studio816](https://discuss.emberjs.com/u/studio816)\
**Post date:** [April 17, 2013, 6:55pm UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/2 "2013-04-17T18:55:13Z")

</div>

I think I found the answer:

```
App.ApplicationRoute = Ember.Route.extend({
setupController : function(){
this.controllerFor('settings').set('model', data);
}
});

```

---

<div class="post-metadata">

**Author:** ![craig\_teegarden](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/craig_teegarden/32/14340_2.png) [@craig\_teegarden](https://discuss.emberjs.com/u/craig_teegarden)\
**Post date:** [April 17, 2013, 8:35pm UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/3 "2013-04-17T20:35:21Z")

</div>

You can use `deferReadiness()` to keep the app from starting until you have completed some startup task:

> **[Application - 4.6 - Ember API Documentation](https://api.emberjs.com/ember/release/classes/Application)**
>
> An instance of Application is the starting point for every Ember application. It instantiates, initializes and coordinates the objects that make up your app. Each Ember app has one and only one Application object. Although Ember CLI creates this...

---

<div class="post-metadata">

**Author:** ![stusalsbury](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/stusalsbury/32/14560_2.png) [@stusalsbury](https://discuss.emberjs.com/u/stusalsbury)\
**Post date:** [April 18, 2013, 7:25pm UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/4 "2013-04-18T19:25:38Z")

</div>

@craig_teegarden: thanks, that helps.

Does anyone know a way to conditionally put routing on hold (block the script) for a _specific_ route? I’m looking at the [router code](https://github.com/emberjs/ember.js/blob/v1.0.0-rc.2/packages/ember-routing/lib/system/router.js#L164) and I see

```
  if (!handler) {
    if (name === 'loading') { return {}; }
    if (name === 'failure') { return router.constructor.defaultFailureHandler; }

    container.register(routeName, DefaultRoute.extend());
    handler = container.lookup(routeName);
  }

```

Perhaps the empty object being returned if the routes name is “loading” is they key? I’m a little puzzled about where the name “loading” is coming from. If this is the place to handle what happens for yet-to-be-loaded Routes, then it might be nice to have a hook to do something other than route to nothingness.

In addition, it looks like once Ember concludes that there isn’t a handler for a route (i.e. !handler is true and the name isn’t “loading”), it will thenceforth not re-check for it, and just return the DefaultRoute. This is fine if there will never be a Route, but what if one is established later? Is there a means to undo this conclusion?

Or perhaps I’m misunderstanding the whole thing?

---

<div class="post-metadata">

**Author:** ![gjastrab](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gjastrab/32/14629_2.png) [@gjastrab](https://discuss.emberjs.com/u/gjastrab)\
**Post date:** [April 23, 2013, 2:18am UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/5 "2013-04-23T02:18:46Z")

</div>

I’m only just getting into Ember, but was reading through some of the tests last week and recalled this test [about the Loading state](https://github.com/emberjs/ember.js/blob/master/packages/ember/tests/routing/basic_test.js#L458) which I made a note to myself to look into later.

If this is meant for initial loading as you’re asking, perhaps something should be added to the guides describing the Loading state and how to use it?

I wonder if this loading state should be used along with deferReadiness?

---

<div class="post-metadata">

**Author:** ![elsurudo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/elsurudo/32/15420_2.png) [@elsurudo](https://discuss.emberjs.com/u/elsurudo)\
**Post date:** [January 11, 2014, 9:04pm UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/6 "2014-01-11T21:04:25Z")

</div>

I found that “setupController” on my ApplicationRoute was called _after_ the “model” method on my IndexController, which messed things up. Basically, my preloaded data wasn’t ready for IndexRoute, and IndexRoute’s “model” method depended on the preloaded data.

I moved my data preloading to ApplicationRoute’s “model” method, and it seems to work. However, I just started developing my app, so not sure if this will continue to be feasible.

---

<div class="post-metadata">

**Author:** ![BenMorganIO](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/benmorganio/32/10693_2.png) [@BenMorganIO](https://discuss.emberjs.com/u/BenMorganIO)\
**Post date:** [April 14, 2015, 12:51am UTC](https://discuss.emberjs.com/t/preloading-data-before-routing/1014/7 "2015-04-14T00:51:14Z")

</div>

With `data` what are you referring to? If a developer grabs the data via a GET, where would they do so?
