By Oleksii Rudenko July 3, 2015 1:15 AM
Ember.js: Process Click on Link-To Helper if No Transition Happens

For 1 year of development with Ember I never needed something like this until yesterday. The task was to attach a handler to the link-to helper that would run when there is no transition fired by the helper itself (e.g. when the link-to helper points to the current route). In particular, I needed to scroll to the top of the window when no transition happens.

Here is a simple solution: add {{action}} helper to the content of the link-to helper and check what the current route is.

actions: {
  clickOnLink: function() {
    if (this.get('currentPath') === 'index') {
       alert('click caught on index. No transition');
    }
  }
}

See a full demo here:

See the Pen Ember JS 1.13.2 by Oleksii Rudenko (@OrKoN) on CodePen.