I use a NavigationView as the root panel. And the thing I try to accomplish is to push views onto my root panel as the user navigates deeper into my application, and pop them of when the user goes back.
Here is a simple examples showing my problem: I have one type of view showing some entry details.
Ext.define('MyApp.view.EntryDetails', {
extend: 'Ext.Panel',
xtype: 'entrydetails',
config: {
tpl: '<div>{id}</div>'
}
});
I also have a controller configured to listen to the following route: "entry/:id", and push a new entrydetails view onto the navigationstack (NavigationView) when this route matches.
Ext.define('MyApp.controller.EntryDetails', {
extend: 'Ext.app.Controller',
config: {
routes: {
'entry/:id': 'showEntry'
},
refs: {
navview: 'mynavigationview'
},
},
showEntry: function(id){
this.getMain().push({
xtype: 'entrydetails',
data: {id:id}
});
}
});
Okay, this is working fine. Now lets first assume I navigate to: index.html#entry/1. This will push a new view onto the stack, just as I want. I then click another link index.html#entry/2. Another view is pushed onto the stack, this is also the intended behavior. Now the problem appears when I click the BROWSERS back button. This changes the url to index.html#entry/1 and pushes yet another view onto my stack. I wanted to pop a view instead of adding another. If I press the toolbars backbutton the view is popped just as I wanted, but this is not the case with the browsers back button.
I do understand why this is happening: The Sencha touch framework do not know if the url change was due to me pressing another link with the same url as the previous browser history url, or if I was pressing the back button on my browser. And all my code knows is that is should push another view onto the stack when it sees an url change to "entry/:id".
What is the best way to solve this problem. How do I detect that the back button of the browser was pressed and the pop a view from my navigationview.
I have thought of checking if the changed url was simular to a view further down on my navigation stack, but I'm not sure if that's the way to do it.
Any help / discussion on the topic is appreciated!