How to prevent multiple event listeners on Liferay SPA SennaJS?

458 views Asked by At

I want to fire a function every time I change a page in Liferay.

Liferay.on('endNavigate', function(event) {
    functionToExecuteOnEveryPage();
});

It works, but every time I change the page the event 'endNavigate' is invoked multiple times.

enter image description here The first time I change the page the function is executed once, and the second time I change the page the function is executed two times, and the third time I change the page the function is executed three times, and so on..

How can I prevent this behavior?

0

There are 0 answers