首页 > 解决方案 > 无法初始化路由器

问题描述

我在尝试初始化 SAPUI5 的路由器时遇到问题。这是我的 webapp 文件夹结构: webapp 文件夹

在清单的底部,我定义了所有路由配置、路由和目标:

"routing": {
    "config": {
        "routerClass": "sap.m.routing.Router",
        "viewType": "XML",
        "viewPath": "ar.com.ordago.FSOT.view",
        "controlId": "app",
        "controlAggregation": "pages",
        "transition": "slide",
        "async": true
    },
    "routes": [{
         "pattern": "",
         "name": "appHome",
         "target": "home"
    }],
    "targets": {
         "home": {
                "viewId": "home",
                "viewName": "Home",
                "viewLevel" : 1
        }
    }

我的 App.view:

<mvc:View
controllerName="ar.com.ordago.FSOT.controller.App"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:form="sap.ui.layout.form"
xmlns="sap.m">
  <App id="app"/>
</mvc:View>

我的家.view

<mvc:View
controllerName="ar.com.ordago.FSOT.controller.Home"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns="sap.m">
    <pages>
        <Page
            id="page"
            title="{i18n>title}">
            <content>
            </content>
         </Page>
    </Pages>
</mvc:View>

然后在 Component.js 我尝试创建路由器的实例(我包括它的所有开头以防万一):

sap.ui.define([
"sap/ui/core/UIComponent",
"sap/m/MessageToast",
"sap/ui/Device",
"sap/ui/model/json/JSONModel",
"./model/models",
"./model/formatter"
], function(UIComponent, MessageToast, Device, JSONModel, models) {
"use strict";

return UIComponent.extend("ar.com.ordago.FSOT.Component", {

    metadata: {
        manifest: "json"
    },

    /**
     * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
     * @public
     * @override
     */

    init : function() {
        // call the base component's init function
        UIComponent.prototype.init.apply(this, arguments);
        // set the device model
        this.setModel(models.createDeviceModel(), "device");
        // create the views based on the url/hash
        this.getRouter().initialize();


    }

当我运行 webapp 时,出现以下错误:无法读取未定义的属性“初始化”

我在这里搜索,很多人都有类似的问题。但是对于建议的每个解决方案,问题是在 component.js 的 init 函数中没有 UIcomponent.prototype... 调用,但我确实有它,所以我不知道接下来要做什么来解决这个问题。

我在这里感谢您的帮助!

标签: routessapui5

解决方案


解决了。

问题是 manifest.js 中使用的缩进已损坏。所有与路线和导航相关的信息都在节点“sap.ui5”的同一级别,当它们需要位于该节点的较低级别时。本质上,由于我混合了许多技术,因此我没有通过 SAP WebIDE 进行编码。但是为了解决这个问题,我在 WebIDE 中加载了项目,并且能够看到错误。我想在处理 SAPUI5 控件时最好通过 WebIDE 来维护它。


推荐阅读