Search code examples
ember.jsember-router

In Ember.js, how can I force a route to be in the loading substate?


Is it possible to reenter the loading state manually?

Right now I have a template that matches the loading rule mentioned at their webpage:

Ember will find a loading route at the above location if

[...]

a properly-named loading template has been found, e.g.

bar/loading
foo/loading
loading

When transitioning to the page, it uses this template, which is great. However, I would like to enter that same loading state while my web request busy. Currently, I am reimplementing that template in the page and toggling it, which duplicates code. I would rather tell ember when I am in loading state or not manually.

Edit: In response to comment, the web requests both set and push data to the model (search button and "infinite scroll" pagination)


Solution

  • You could use transitionToRoute() to transition into (and out of) a loading route while your request is in progress.