Search code examples
javascriptjqueryweb-applicationsember-clihashchange

Ember-CLI - Detect hash-change function in ember


I'm relatively new to ember I've come across a scenario in which a class name should remove from the body tag while the window location changes and I figured out some code snippet to do so.

Ember.$(window).on('hashchange',function(){ 
      Ember.$('body').removeClass("someclass");
   });

And it doesn't work.


Solution

  • I've solved the issue by using willTransition function in Ember-Cli. Heres the code snippet to perform DOM manipulation while changing the route.

    willTransition: function() {
      Ember.run.next(() => {
         Ember.$('body').removeClass("someclass");
      });
    }