SAPUI5路由:无法读取属性'初始化'未定义的

时间:2016-06-09 07:14:38

标签: javascript url-routing sapui5

我在创建路由器时遇到问题。我每次都会收到错误Cannot read property 'initialize' of undefined

这是我在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
                },

如果我尝试var router = sap.ui.core.routing.Router.getRouter();它就一样。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:3)

您缺少这行代码:

UIComponent.prototype.init.apply(this, arguments);

在初始化路由器之前,您需要调用父进程的init函数。