Skip to content

Instantly share code, notes, and snippets.

@ffleige
Last active July 26, 2017 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffleige/1f080e5c0769085569188302b2e12040 to your computer and use it in GitHub Desktop.
Save ffleige/1f080e5c0769085569188302b2e12040 to your computer and use it in GitHub Desktop.
openui5 - Access to id of current route
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