Would be happy about an example of what is the difference between the following SAPUI5 routing approaches:
sap.ui.core.routing.Route
:
attachMatched()
attachPatternMatched()
sap.ui.core.routing.Router
:
attachRouteMatched()
attachRoutePatternMatched()
API says for attachMatched()
and attachPatternMatched()
nothing about any difference.
API says for attachRouteMatched()
:
Attach event-handler
fnFunction
to therouteMatched
event of thissap.ui.core.routing.Router
.
API says for attachRoutePatternMatched()
:
Attach event-handler
fnFunction
to theroutePatternMatched
event of thissap.ui.core.routing.Router
. This event is similar to route matched. But it will only fire for the route that has a matching pattern, not for its parentRoutes
.
E.g. could use
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("sap.ui.demo.wt.controller.Detail", {
onInit: function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("detail").attachMatched(this._onObjectMatched, this);
// oRouter.attachRouteMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
this.getView().bindElement({
path: "/" + oEvent.getParameter("arguments").invoicePath,
model: "invoice"
});
}
});
});
or
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("sap.ui.demo.wt.controller.Detail", {
onInit: function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this);
// oRouter.attachRoutePatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
this.getView().bindElement({
path: "/" + oEvent.getParameter("arguments").invoicePath,
model: "invoice"
});
}
});
});
No difference to see. Don't get «But it will only fire for the route that has a matching pattern, not for its parent Routes.» Thought attachRouteMatch()
would fire only as well for the route that has a matching pattern.