我遵循了关于SAP学习中心的指南,并且也使用了教程,但是我仍然无法使路由工作。想知道Web IDE的安装是否有问题吗?
component.js文件
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device",
"com/s5/mal/routingRouting/model/models"
], function(UIComponent, Device, models) {
"use strict";
return UIComponent.extend("com.s5.mal.routingRouting.Component", {
metadata: {
manifest: "json"
},
init: function() {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// set the device model
this.setModel(models.createDeviceModel(), "device");
this.getRouter().initialize();
}
});
});
main.view.xml文件
<mvc:View controllerName="com.s5.mal.routingRouting.controller.Main" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m">
<App id="idApp" />
</mvc:View>
view1.view.xml
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="com.s5.mal.routingRouting.controller.View1"
xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Title">
<content>
<Text text="View1" />
<Button text="Next View" press="onPress" />
</content>
</Page>
</mvc:View>
view1.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("com.s5.mal.routingRouting.controller.View1", {
getRouter: function(){
return sap.ui.core.UIComponent.getRouterFor(this);
},
onPress: function (oEvent){
this.getRouter().navTo("View2");
}
});
});
manifest.json
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewPath": "com.s5.mal.routingRouting.view",
"controlId": "idApp",
"viewType": "XML",
"controlAggregation": "pages",
"transition": "slide"
},
"routes": [{
"name": "View1",
"pattern": "",
"titleTarget": "",
"greedy": false,
"target": ["View1"]
}, {
"name": "View2",
"pattern": "",
"titleTarget": "",
"greedy": false,
"target": ["View2"]
}, {
"name": "notFound",
"pattern": "",
"titleTarget": "",
"greedy": false,
"target": ["notFound"]
}],
"targets": {
"View1": {
"viewId": "View1",
"viewType": "XML",
"transition": "slide",
"clearAggregation": true,
"viewName": "View1",
"viewLevel": 1
},
"View2": {
"viewId": "View2",
"viewType": "XML",
"transition": "slide",
"clearAggregation": true,
"viewName": "View2",
"viewLevel": 2
},
"notFound": {
"viewType": "XML",
"transition": "slide",
"clearAggregation": true,
"viewName": "NotFound"
}
}
}
即使尝试其他教程,我似乎也无法找出问题所在,但最终却一无所获。当我按下按钮时,我没有任何反应。就像它永远不会运行一样,当我对其进行调试时,它会通过我的“ onPress”按钮运行,而控制台日志上没有错误。
我只是想使路由工作正常,我还没有做到这一点。
答案 0 :(得分:0)
您所有的路线都为空模式。如果导航到路由“ view2”,则其模式将添加到URL中的#,然后进行路由检查,找到与模式=>相匹配的路由并找到“ view1”
将view1模式保留为空,将模式添加到其他路线。