The widget mentioned by Freek can be used for unintended page closures.
The widget allows you to trigger a microflow to perform any necessary actions.
For the intended close actions of a page make sure to replace the standard buttons with buttons calling a microflow to perform the necessary actions.
If you are developing for native then you can use the App Events widget as part of the NativeMobileResources module. This widget has an configuration for page load & unload (as per the latest version).