sapui5路由(由于该路由不存在,因此无法导航到名称为xx的路由)

时间:2019-02-15 08:18:47

标签: sapui5

我有4个视图,主要视图是登录页面。因此,当用户单击具有正确凭据的登录按钮时,它将重定向到主页页面。但是我收到错误消息由于该路由不存在,无法导航至名称为main

下面是我的manifest.json路由配置:

    "routing": {
        "config": {
            "routerClass": "sap.m.routing.Router",
            "viewType": "XML",
            "async": true,
            "viewPath": "UI.sap_portal.view",
            "controlAggregation": "pages",
            "controlId": "app",
            "clearControlAggregation": false,
            "transition": "slide" 
        },
        "routes": [
            {
                "name": "Routemain",
                "pattern": "Routemain",
                "target": [
                    "Targetmain"
                ]
            } 
        ],
        "targets": {
            "Targetmain": {
                "viewType": "XML",
                "transition": "slide",
                "clearControlAggregation": false,
                "viewId": "login",
                "viewName": "login",
                "viewLevel": 1
            },
            "main": {
                "viewId": "main",
                "viewType": "XML",
                "viewName": "main",
                "viewLevel": 1
            },
            "masterData": {
                "viewType": "XML",
                "viewName": "masterData"
            },
            "purchasing": {
                "viewType": "XML",
                "viewName": "purchasing"
            } 
        }
    }

这是我的login.controller.js代码:

        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.navTo("main");

如果我将其放入manifest.json

        "routes": [
            {
                "name": "Routemain",
                "pattern": "Routemain",
                "target": [
                    "Targetmain"
                ]
            },
            {
                "name": "main",
                "pattern": "",
                "target": "main"
            }

        ]

它会自动重定向到我的主页,应该是登录页面。抱歉,我是sapui5的新手。

2 个答案:

答案 0 :(得分:0)

尝试将main的目标更改为:            "main": { "viewType": "XML", "viewName": "main" }

答案 1 :(得分:0)

您的路线名称是Routemain。那就是您应该在navTo上使用的内容:navTo(“ Routemain”)。

这将加载Targetmain中定义的视图。

您没有名为“ main”的路由,因此出错。