I have a requirement to alert the user when they try to leave a form with unsaved changes. Our Napili forms are individual community pages so this means we need to detect/confirm (in Lightning) a page transition/navigation event.

Using the Lightning chrome extension I can see lots of good candidate events for this e.g. force:hidePanel, siteforce:changeView etc.

When I try to register a handler for these events, I can't even save the handler.

Is there an example of how to do this somewhere or is there a reliable (ideally supported) way of detecting navigation between community pages?


This is a follow-on from Fast js navigation in Communities using Lightning/Napili

1 Answer 1


I found a workaround to this in case anyone find's it useful. It's pretty simple.

Find a component that is always displayed e.g. the header or footer. In there, add a handler for the aura:doneRendering event. Also add a path string attribute.

In the controller you can compare "path" to window.location.pathname and if they differ, then you know that the user has changed location. Update the path immediately and then do whatever you need e.g. fire a custom event.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .