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",
});
});

@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";
			})
	);
});
1 Like

Dear Intregal,

Thanks for your help, It is working fine.