[SOLVED]How to make back button on Android and browser to work?

How do you control the back button on Android so if you in a view have a menu, and from there navigate to a couple of subpages and then go back, and so it stops on the menu page and not exit the app?
With this it is going back but not stopping at the menu page.

$$(window).on(‘popstate’,function(){
app.dialog.alert(“back button on android clicked”)
mainView.router.back();

});

Any input appreciated, thanks.

Ok, so this works in browser and in fullscreen web app on Android.
So it goes back if you click the browser back button or the hardware back button on Android, and when it comes back to the menu page in the view it is not exiting the app. Just how I want it.

delete history.pushState;
var obj={name:“anyname”,url:window.location.href};
history.pushState(obj,obj.name,obj.url);
$$(window).on(‘popstate’,function(){

var view = app.views.current;
//var le = view.history.length;
//var na = view.name;
//console.log (view.name,‘this is current view’)
if (!view) return;
if (view.history.length > 1) {
if(view.name===‘mainView’){
mainView.router.back();
}
if(view.name===‘view3’){
view3.router.back();
}

return;
}
});

There is a backbutton event in android Exit App when no page to go back [v1] vue