Checking validation before navigation by using webix.ajax.get() in app:guard

Dear Developer,

Is it possible to check the validation by using webix.ajax.get("/something") inside app:guard?
May I know, the correct way to check before the next route.
Below is an example of what I want to do it. But, It is not working.

app.attachEvent("app:guard", function(url, view, nav){
webix.ajax().get("/isvalid").then(b => {
if(!b.isvalid){
nav.redirect ="/main",
}
}).catch((err) => {
nav.redirect ="/main",
});
});

Comments

  • @NaingOo
    try to use nav.confirm promise

    app.attachEvent("app:guard", function (url, view, nav) {
        nav.confirm = nav.confirm.then(() =>
            webix
                .ajax()
                .get("/isvalid")
                .then((b) => {
                    if (!b.isvalid) {
                        nav.redirect = "/main";
                    }
                })
                .catch((err) => {
                    nav.redirect = "/main";
                })
        );
    });
    
  • Dear Intregal,

    Thanks for your help, It is working fine.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion