Dialog before page closes

Hello,

I want the users to show a dialog when they close a page with the back button. How can I prevent the page to go back when the dialog is shown?

$(".back").click(function(){
app.dialog.confirm('Are you sure?', function () {
	app.views.current.router.back();
});
});

Add prevent-router class to that this link to prevent automatic routing on click