{{linkTo}} clicks do not propagate up to the containing view


#1

I’m trying to listen in to the click of a {{linkTo}}, so that I can do additional stuff (basically do an animation) besides loading the new template.

I’ve figured out that i can put my code in renderTemplate() of the route, but the problem with that is that the effect will happen for every link to that route (which is not what I want). I want the scroll to only trigger for a specific {{linkTo}}.

I’ve tried wrapping the specific {{linkTo}} in a {{view}} - but it seems like the click() is being skipped / not triggered in the view when it comes from a {{linkTo}}… What should I do? I suppose i could possibly consider replacing the {{linkTo}} with an ‘<a>’ element, but I would have to replicate the effect of the {{linkTo}}. I’m not exactly sure that’s recommended, or even possible (a ‘this.transitionTo()’ doesnt work in the view code!)


#2

If you want to apply certain actions to a link-to helper that only has to do with the view/presentation, I would use this inside the view in question:

didInsertElement: function() {
    this.$().delegate('.link-class', 'click', this.linkClickHandler);
},
linkClickHandler: function(event) {
    //Do as you wish
}

That way you can handle the presentation without mucking up the workings of Ember, while still preserving the functionality of the link-to helper.