Sapui5 无法读取属性';setHash';未定义的类型-SAP UI5

Sapui5 无法读取属性';setHash';未定义的类型-SAP UI5,sapui5,Sapui5,我正在尝试导航到“BadConfiguration”页面,其中一些用户属性匹配。 但我一直无法读取未定义错误的属性“setHash”。 我尝试进行一些更改,然后出现了替换哈希错误。它只是一个页面应用程序,如果用户不是特定的用户,我必须显示错误的配置页面 编辑:更改以正确反映路由器名称。但问题是——只有当我把那个呼叫放在其他地方导航时,它才会起作用。例如,若我在页面上给出一个按钮,点击该按钮,我调用其中的一个函数,我调用导航。 如果我不这样做,并尝试给出在init()或initializeView

我正在尝试导航到“BadConfiguration”页面,其中一些用户属性匹配。 但我一直无法读取未定义错误的属性“setHash”。 我尝试进行一些更改,然后出现了替换哈希错误。它只是一个页面应用程序,如果用户不是特定的用户,我必须显示错误的配置页面

编辑:更改以正确反映路由器名称。但问题是——只有当我把那个呼叫放在其他地方导航时,它才会起作用。例如,若我在页面上给出一个按钮,点击该按钮,我调用其中的一个函数,我调用导航。 如果我不这样做,并尝试给出在init()或initializeView()中导航的行代码,它将返回setHash错误

Manifest.json

Component.js

有两个视图,即->G_Table.xml和BadConfiguration.xml

G_Table.xml


尝试导航到页面时,需要使用路由器名称。这里的问题是,您正试图导航到一个给出其目标名称的页面

你必须试试

this.getOwnerComponent().getRouter().navTo(“坏配置”…)

有关布线工作原理的示例: 此外,如果您知道何时调用此视图,我认为在这种情况下不需要该模式


让我知道这是否有帮助

不要在onInit内进行导航

onInit事件应用于初始化有关其控制器的属性。在触发onInit时,其他视图和其他控制器尚未“知道”SAPUI5

在onInit事件上,注册routeMatched事件,然后在routeMatched上执行导航

像这样:

sap.ui.define(['sap/ui/core/mvc/Controller'],
    function(Controller) {
    "use strict";

    var that;

    return Controller.extend("sapui5Example.home", {



                 onInit: function () {

                that = this;
                 sap.ui.core.UIComponent.getRouterFor(that).getRoute('rtHome').attachPatternMatched(
                    onRouteOrSubRoutesMatched);
            }





    });

      function onRouteOrSubRoutesMatched() {

        sap.ui.core.UIComponent.getRouterFor(that).navTo('yourOtherRoute');

        }


});
这是一个扑克牌:

谢谢,当我将其更改为路由器名称时,它会正常工作。但只有当我把那个电话转到其他地方去导航时,它才会起作用。例如,若我在页面上给出一个按钮,点击该按钮,我调用其中的一个函数,我调用导航。如果我不这样做,并尝试给出在init()或initializeView()中导航的行代码,它将返回setHash错误。这个.getOwnerComponent().getRouter()返回什么。?
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();

    }
<mvc:View controllerName="Plant_Data_Plant_Data.controller.G_Table"
     xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" 
    xmlns:core="sap.ui.core" displayBlock="true" xmlns="sap.m">
    <App id="app">
        <pages>
        <Page title="Plants" showHeader="true">
return Controller.extend("Plant_Data_Plant_Data.controller.G_Table", {
        onInit: function() {
        var userModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");
        this.getView().setModel(userModel, "userapi");

 // here the aim is if some properties satisfy, then route to bad 
   configuration

  if(true)
 {
 this.getOwnerComponent().getRouter().navTo("bc", {}, false);

 //I get setHash undefined error here
  }
  this.initializeView();
    },


    initializeView: function() {

        this.populateTable();

    },
sap.ui.define(['sap/ui/core/mvc/Controller'],
    function(Controller) {
    "use strict";

    var that;

    return Controller.extend("sapui5Example.home", {



                 onInit: function () {

                that = this;
                 sap.ui.core.UIComponent.getRouterFor(that).getRoute('rtHome').attachPatternMatched(
                    onRouteOrSubRoutesMatched);
            }





    });

      function onRouteOrSubRoutesMatched() {

        sap.ui.core.UIComponent.getRouterFor(that).navTo('yourOtherRoute');

        }


});