我使用MVC模式在SAP Cloud平台上创建了一个HTML5应用程序。 在index.html文件中,该部分中添加了一个javascript文件引用。在这个JS文件中,我希望能够访问应用程序的路由器,从外部源(使用Web套接字)引导应用程序。该文件将包含处理传入推送消息并导航到所需页面的所有逻辑。
我很难让这个文件中的路由器对象导航,有没有办法从sap核心获取路由器对象,...?
由于
答案 0 :(得分:0)
通过在component.js文件中注册路由器然后在另一个文件中访问它来解决它:)
-Component.js
sap.ui.define([
"sap/ui/core/UIComponent"
], function (UIComponent) {
"use strict";
return UIComponent.extend("be.myapp.Component", {
metadata : {
manifest: "json"
},
init : function () {
// call the init function of the parent
UIComponent.prototype.init.apply(this, arguments);
var router = this.getRouter();
this.routeHandler = new sap.m.routing.RouteMatchedHandler(router);
router.register("appRouter"); // Assign a name to Router, so that we can access it in all controllers by using this name
router.initialize(); // Initialise the Router
}
});
});
var oRouter = sap.ui.core.routing.Router.getRouter("appRouter");
oRouter.navTo("overview", {}, true);