I have been trying to route from View1 to View2. My code is the same as what is given in the SAPUI5 SDK, with some minor changes according to my project. I tried multiple solutions given on the internet but none of them worked.
View1.controller.js
onNav: function (oEvent) {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("View2");
//return this.getOwnerComponent().getRouter().navTo("View2");
},
manifest.json
"routes": [
{
"pattern": "",
"name": "View1",
"target": "View1"
},
{
"pattern": "View2",
"name": "View2",
"target": "View2"
}
],
"targets": {
"View1": {
"viewId": "View1",
"viewName": "View1"
},
"View2": {
"viewId": "View2",
"viewName":"View2"
}
}
The error shown is:
sap.ui.core.UIComponent.getRouterFor is not a function
var oRouter = this.getOwnerComponent().getRouter();
– Marc