Nativescript webview and android back button

倖福魔咒の 提交于 2019-12-04 10:45:20

You need to handle Android hard button like this:

First import dependencies :

import { AndroidApplication, AndroidActivityBackPressedEventData } from "application";
import * as application from "application";

Then add this code :

application.android.on(AndroidApplication.activityBackPressedEvent, (data: AndroidActivityBackPressedEventData) => {
  data.cancel = true; // prevents default back button behavior
  console.log("webview can go back "+this.webView.canGoBack);
  if (webView.canGoBack) //if webview can go back
      webView.goBack();
  else
      this.router.backToPreviousPage();
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!