Created
February 8, 2017 08:36
-
-
Save cschuff/e953450fa42650aee78fbeb7939ccdce to your computer and use it in GitHub Desktop.
Auto-attach to patternMatched event on correct sap.ui.core.routing.Route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////// | |
// Controller Lifecycle | |
onInit: function () { | |
this.getRouter().attachRoutePatternMatched(this.onAnyRoutePatternMatched, this); | |
}, | |
onExit: function () { | |
this.getRouter().detachRoutePatternMatched(this.onAnyRoutePatternMatched, this); | |
this.getRouter().getRoute(this.routeName).detachPatternMatched(this.onRoutePatternMatched, this); | |
}, | |
//////////////////////////////////////////////////////////// | |
// Navigation | |
onAnyRoutePatternMatched: function (oEv) { | |
// store route name when first matched | |
if (!this.routeName) { | |
this.routeName = oEv.getParameter("name"); | |
// attach pattern matched now that we now this views route name | |
this.getRouter().getRoute(this.routeName).attachPatternMatched(this.onRoutePatternMatched, this); | |
// manually trigger attachPatternMatched since we already missed the first event here | |
this.onRoutePatternMatched(oEv) | |
} | |
// view is left, clean up here | |
if (oEv.getParameter("name") !== this.routeName) { | |
this.getView().unbindElement(); | |
} | |
}, | |
onRoutePatternMatched: function (oEv) { | |
// do reoccuring view init here (treat like onBeforeShow) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment