重新加载相同的路由路径不起作用

Reload the same route path not work

我想使用路由重新加载相同的路径; 在 onInit 中,我有 routeMatched 函数,我可以在其中调用服务器:

this.router.attachRoutePatternMatched(this._handleRouteMatched, this);

这是电话:

var idProduct= "p1"
this.router.navTo("product", {
            id_product: idProduct
});

url 路径是:.../index.html#/product/p1

我第一次调用 navTo 函数 _handleRouteMatched 启动。对!

但是,如果在相同的路径中我想要(通过一个按钮)重新加载相同的产品我想通过 navTo 函数来完成,但是 在第二种情况下 函数 _handleRouteMatched 没有启动 .

什么是解决我的问题的正确方法?我不喜欢在按下按钮时在逻辑中写入 _handleRouteMatched 的内容。 我想一直通过路由器

ui5 中的路由器足够智能,可以检测到您的 navTo() 将使用当前参数转到当前路线。在这种情况下路由器触发路由没有任何意义,因为你已经在那里了。如果您想再次 reload/refresh 相同的产品,那么您应该获得对相应绑定的引用并对该绑定调用 refresh() 。如果您使用的是 ODataModel,这应该会自动从服务器重新获取数据。有关详细信息,请参阅 https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Binding.html#refresh