How to stop Senna.js from calling multiple jQuery event handlers

304 views Asked by At

I have developed a SPA website using Senna.js and it works great! However, I have recently noticed that it doesn't remove jQuery event handlers when leaving the page. So I have all kinds of functions firing twice when I navigate back to a page I have already visited.

I fixed most of my personal code by doing this

$("#element").off("event").on("event", etc.)

But there are thousands of lines of other people's code which is also powering my website and I am worried that they are firing twice as well.

Does anybody on SO have any insight or approaches to handling this?

1

There are 1 answers

0
user2551403 On BEST ANSWER

You can detach event handlers using Senna's lifecycle events. For example:

var app = new senna.App();

app.on('beforeNavigate', function() {
// detach jQuery event handlers
});