The router of my application looks like this (it's CoffeeScript):
App.Router.map () ->
@resource 'conversations', { path: '/' } ->
@resource 'conversation', { path: ':conversation_id' }
@route 'new'
So, in my app, I have paths like /new
, /1
, /2
, etc.
I would like to detect a transition from /1
to /2
to make some initializations in my view (basically, put the focus on a textarea field). Unfortunately, as /1
and /2
use the same route, it seems nearly impossible to detect that transition.
I tried by using didInsertElement
in the view (as described here) or by observing currentPath
in the controller (as described here). It works fine if I go from /new
to /1
(different routes) but not if I go from /1
to /2
.
I found this gist suggesting to use the StateManager
but it seems outdated (and I'm not sure it's really what I need).
What do you suggest me to do?
EDIT
It seems that setupController
is called every time so I decided to overload it like this:
App.ConversationRoute = Ember.Route.extend {
setupController: (controller, model) ->
controller.set 'model', model
# do something here?
}
And I want the init
method in my view to be called:
App.ConversationView = Ember.View.extend {
init: ->
@$('form textarea').focus()
}
But I still can't figure out how to make these two things work together (it's a problem because I read that the controller is not supposed to know about the view).
Thank you for your help!