0
votes

I'm looking for a way to hook into the router as it transitions to any given leaf resource during app init. In other words, I want to run a little init routine every single time an app is loaded, no matter what the "incoming" url state is.

Given a router such as this:

App.Router.map ->
  @resource "donkeys"
  @resource "camels"

When the app is loaded (for the first time) with a dangling url such as this:

localhost:9000/#/donkeys

-- or --

localhost:9000/#/camels

I want the same router-level code to be called.

My first guess was to try something like this (this doesn't work):

App.IndexRoute = Ember.Route.extend

  activate: ->
    App.callTheBeastsOfBurden()

... but it turns out that IndexRoute is not being traversed. I only see the log message Transitioned into 'donkeys'

In ye olde days, there was this "root route" concept that you could hook in to. If I recall, it looked something like this (this is old and "wrong"):

App.Router = Em.Router.extend
  root: Em.Route.extend
    connectOutlets: ->
      App.callTheBeastsOfBurden()

So what's the Router v2 approved method of accomplishing the same?

1
try App.ApplicationRoute = Em.Router.extendMilkyWayJoe
lol you beat me by 12sMike Grassotti
Just noticed that :P +1 thoMilkyWayJoe

1 Answers

1
votes
App.ApplicationRoute = Ember.Route.extend

  activate: ->
    App.callTheBeastsOfBurden()