有没有办法在sapui5中制作受保护的路线

Is there a way to make protected route in sapui5

getRouter: function () {
        return UIComponent.getRouterFor(this);
      },
onInit: function () {
   firebase.auth().onAuthStateChanged((user) => {
     if (!user) {
       this.getRouter().navTo("login");
         }
        });
      }

有没有办法让我的路由受到保护,当我第一次输入浏览器时没有问题,我被重定向了,但是如果我退出组件,然后手动输入浏览器/admin,我是没有重定向,所以 onInit 只工作一次。我是 sapui5 的新手,在 React 中它是不同的。有人可以帮忙解释一下是否有办法在路线上进行某种保护。谢谢

要监听的正确事件是 patternMatched

这是如何保护名为“myProtectedRoute”的单个路由的示例:

onInit: function () {
    this.getRouter().getRoute("myProtectedRoute").attachPatternMatched((event) => {
        if (user.isAuthenticated) {
           // load and show data
        } else {
           this.getRouter().navTo("login");
        }
    })
}

如果您希望在任何路由匹配时收到通知,您可以在本教程中阅读更多内容https://openui5.hana.ondemand.com/topic/4a063b8250f24d0cbf7c689821df7199