SAPUI5 limits page visibility

Is there a way / best practice to hide inaccessible pages from users in SAPUI5?

Let's look at an example. I have a complex application with a user login page. Here, customers can enter the application, and their role data is retrieved from the backend system. Based on these roles, some users are not allowed to create a new object. Only registered users should see application pages. I use routing, so direct links may be available to functions like editing.

I am currently using the onRouteMatched event handler in Component.js, which checks the current store of user sessions. If no user session is found, it redirects the request to the login page.

The problem is that before you go to the login page, the requested page is displayed for one or two seconds. This is really ugly.

Where should I implement this functionality? Is there a hook method for this use case?

It seems to me that I need a hook method that is called before displaying the view associated with this route and redirects the call to the login page. Unfortunately, I did not find a useful document in this section.

Thanks!

+4
source share
2 answers

The approach I used for this is described here. Show purpose

, manifest.json, /. .

"" . , , . -, .

this.getOwnerComponent().getRouter().getTargets().display("edit", {
    fromTarget : "home"
});

, , URL , .

,

yourAppUrl.com/home?navTo=edit

jQuery .

_onPatternMatched: function() {
    var navParam = jQuery.sap.getUriParameters().get("navTo");
    if (navParam === "edit") {
        //handle your user verification here, then display the target
        this.getOwnerComponent().getRouter().getTargets().display("edit", {
            fromTarget : "home"
        });
    }
}
+1

, , . beforeRouteMatched sap.ui.core.routing.Router, ...

. , , :

addRoute, . , , - , . , . HashChanger.setHash.

-!

0

Source: https://habr.com/ru/post/1619844/


All Articles