Вы должны удалять и добавлять EventListener каждый раз, когда вы посещаете представление.
View1:
onInit: function(){
this.getRouter().getRoute("myView1").attachMatched(this._onRouteMatched, this); //Call _onRouteMatched on every visit from myView1
},
_onRouteMatched: function (oEvent) {
document.removeEventListener("keypress"); //Remove the event listener
document.addEventListener("keypress", function onPress(event) { //Add the event listener again with another message
if ( event.keyCode === 50) {
alert("Test View 1");
}
}
View2:
onInit: function(){
this.getRouter().getRoute("myView2").attachMatched(this._onRouteMatched, this);
},
_onRouteMatched: function (oEvent) {
document.removeEventListener("keypress");
document.addEventListener("keypress", function onPress(event) {
if ( event.keyCode === 50) {
alert("Test View 2");
}
}