In Native SF when Tab or Subtab is closed you will be able to do that by subscribing to lightning:tabClosed

[lightning:tabClosed][1] is an application event that indicates a tab has been closed successfully. This event is supported in Lightning console apps only.

    <aura:component implements="flexipage:availableForAllPageTypes" access="global" >
        <lightning:workspaceAPI aura:id="workspace" />  
        <aura:handler event="lightning:tabClosed" action="{! c.onTabClosed }"/> 
    </aura:component>


  [1]: https://developer.salesforce.com/docs/component-library/bundle/lightning:tabClosed/documentation