sencha-touch-2window.onunload

Sencha touch 2 - How to detect when a user navigates from one URL to another?


I am developing a Sencha touch 2 app where I want to detect when the user navigates from one page to another. I want to call a function just like "onunload" in javascript. Any suggestions? Thanks in advance.


Solution

  • That depends on the way you are implementing your navigation.

    1. NavigationView

    http://docs.sencha.com/touch/2.3.1/#!/api/Ext.navigation.View

    The NavigationView is a card based layout where you can pop or push views. There are events like activeitemchange, pop, push etc.

    You can add these events as listener to your component

    Example: listeners : { pop : function(cmp, view, eOpts) {

            ...
    
        }
    }
    

    2. Container Navigation

    You can create a card based container and add/remove the views from this container.

    There you are able to use the activeitemchange, add and remove event.

    But in both cases its mostly the same. You have to set a listener with the event to the outer container (where your views are inside). There you can define your action for switches of views