Skip to Content
0
Jun 09, 2016 at 08:30 AM

Routing: Cannot read property 'initialize' of undefined

3610 Views

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?