Last active
July 26, 2017 08:32
openui5 - Access to id of current route
This file contains 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
sap.ui.define([ | |
"sap/ui/core/routing/Router" | |
], function (Router) { | |
"use strict"; | |
return Router.extend("my.app.MyRouter", { | |
/** | |
* holds the id of current route | |
* @type {string} | |
*/ | |
_sCurrentRoute: null, | |
/** | |
* constructor of router class | |
* @constructor | |
*/ | |
constructor: function () { | |
Router.apply(this, arguments); | |
}, | |
/** | |
* adds a route to the router | |
* @param oConfig | |
* @param oParent | |
*/ | |
addRoute: function(oConfig, oParent) { | |
Router.prototype.addRoute.apply(this, arguments); | |
this.getRoute(oConfig.name).attachMatched( | |
function(oEvent) { | |
this._sCurrentRoute = oEvent.getParameters().name; | |
},this | |
); | |
}, | |
/** | |
* will return the id of current route | |
* @return {string} | |
*/ | |
getCurrentRouteId: function() { | |
return this._sCurrentRoute; | |
}, | |
/** | |
* will return the current route object | |
* @return {sap.ui.core.routing.Route} | |
*/ | |
getCurrentRoute: function() { | |
return this.getRoute(this._sCurrentRoute); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment