Message Boards

Liferay cancel navigation events with JavaScript/Senna.js

Alexander Spielauer, modified 2 Years ago.

Liferay cancel navigation events with JavaScript/Senna.js

New Member Posts: 4 Join Date: 7/21/20 Recent Posts

We have a feature request to cancel navigation events when the user clicks on a Liferay link (e.g. to another liferay page)

In our research we’ve found the SPA Lifecycle events (https://help.liferay.com/hc/en-us/articles/360030709511-Available-SPA-Lifecycle-Events)

We’ve tried multiple approaches with beforeNavigate and beforeUnload but nothing prevented the navigation.

E.g.:

Liferay.SPA.app.on('beforeNavigate', (navigate) => {

navigate.event.stopImmediatePropagation();

                navigate.event.stopPropagation();

              navigate.event.preventDefault();

return false;

})

According to this ticket: https://issues.liferay.com/browse/LPS-68027

preventDefault should prevent the navigation. But it doesn’t work in our case.

Is there a specific way to cancel navigation events inside Liferay with JavaScript/Senna.js?

We are using Liferay 7.2 fixpack 13.

 

 

thanks for any advise :)