I have a problem to create a router. I'll receive the error Cannot read property 'initialize' of undefined
every time.
This is my code in my Component.js:
sap.ui.define([ "sap/ui/core/UIComponent", "sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History", "sap/m/routing/RouteMatchedHandler" ],
function(UIComponent, JSONModel, Router, RouteHandler) {
"use strict";
return UIComponent.extend("myApp.Component", {
metadata: {
routing:{
config: {
viewType:"XML",
viewPath:"myApp.view",
targetControl: "idRoot",
targetAggregation: "pages",
clearTarget: false
},
routes:[{
pattern: "",
name:"Master",
view:"Master"
}]
}
},
init: function(){
var router = this.getRouter(); //Doesn't work
router.initialize(); //ERROR HERE
},
if I try var router = sap.ui.core.routing.Router.getRouter();
it's the same.
Can anybody help me with this?
You are missing this line of code:
UIComponent.prototype.init.apply(this, arguments);
You need to call the parent’s init function before intializing router.