title: How to enable the Back button when using WebView in Nativescript-Vue
body: <p>I am a nativescript-vue novice developer.
  I am currently implementing the Android side code and I succeeded in inserting WebView.
  However, if I touched the back physical button on my phone, the app was terminated immediately.
  When I use WebView in Nativescript-Vue, when I touch the back button, I want to know how to go back without ending.</p>
  <p>I tried the following link. However, an error occurs.
  <a href="https://stackoverflow.com/questions/48646999/nativescript-webview-and-android-back-button">Nativescript webview and android back button</a></p>
  <p>Is it different from NativeScript code and NativeScript Vue code?
  I do not even notice the difference between the two above. Please help me.</p>
  <p>/app/components/App.vue</p>
  <pre class="lang-html prettyprint-override"><code>&lt;template&gt;
      &lt;Page actionBarHidden=&quot;true&quot;&gt;
          &lt;FlexboxLayout&gt;
              &lt;WebView src=&quot;http://example.com&quot; /&gt;
          &lt;/FlexboxLayout&gt;
      &lt;/Page&gt;
  &lt;/template&gt;
  
  &lt;script &gt;
  
  &lt;/script&gt;
  
  &lt;style scoped&gt;
  &lt;/style&gt;
  
  </code></pre>
  <p>/app/main.js</p>
  <pre class="lang-js prettyprint-override"><code>import Vue from 'nativescript-vue'
  import App from './components/App'
  import VueDevtools from 'nativescript-vue-devtools'
  import { AndroidApplication, AndroidActivityBackPressedEventData } from &quot;application&quot;;
  import * as application from &quot;application&quot;;
  import {WebView} from &quot;tns-core-modules/ui/web-view&quot;;
  var webView = new WebView();
  application.android.on(AndroidApplication.activityBackPressedEvent, (AndroidActivityBackPressedEventData) =&gt; {
    AndroidActivityBackPressedEventData.cancel = true; // prevents default back button behavior
    webView.canGoBack = true;
    console.log('back')
  
    // console.log(&quot;webview can go back &quot;+this.webView.canGoBack);
    // if (webView.canGoBack) //if webview can go back
    //   webView.goBack();
    // else
    //   this.router.backToPreviousPage();
  });
  
  if(TNS_ENV !== 'production') {
    Vue.use(VueDevtools)
  }
  
  // Prints Vue logs when --env.production is *NOT* set while building
  Vue.config.silent = (TNS_ENV === 'production')
  
  new Vue({
    render: h =&gt; h('frame', [h(App)])
  }).$start()
  </code></pre>
  <p>Error Message</p>
  <pre><code>An uncaught Exception occurred on &quot;main&quot; thread.
  com.tns.NativeScriptException: 
  Calling js method onBackPressed failed
  
  TypeError: Cannot set property canGoBack of [object Object] which has only a getter
  File: &quot;file:///data/data/io.bagstation.bagstation/files/app/bundle.js, line: 375, column: 20
  
  StackTrace: 
      Frame: function:'module.exports../main.js.application__WEBPACK_IMPORTED_MODULE_3__.android.on.AndroidActivityBackPressedEventData', file:'file:///data/data/io.bagstation.bagstation/files/app/bundle.js', line: 375, column: 21
      Frame: function:'Observable.notify', file:'file:///data/data/io.bagstation.bagstation/files/app/vendor.js', line: 41320, column: 15
      Frame: function:'ActivityCallbacksImplementation.onBackPressed', file:'file:///data/data/io.bagstation.bagstation/files/app/vendor.js', line: 63019, column: 25
      Frame: function:'NativeScriptActivity.onBackPressed', file:'file:///data/data/io.bagstation.bagstation/files/app/vendor.js', line: 60331, column: 21
  
  
      at com.tns.Runtime.callJSMethodNative(Native Method)
      at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
      at com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
      at com.tns.Runtime.callJSMethod(Runtime.java:983)
      at com.tns.Runtime.callJSMethod(Runtime.java:967)
      at com.tns.Runtime.callJSMethod(Runtime.java:959)
      at com.tns.NativeScriptActivity.onBackPressed(NativeScriptActivity.java:50)
      at android.app.Activity.onKeyUp(Activity.java:3049)
      at android.view.KeyEvent.dispatch(KeyEvent.java:2723)
      at android.support.v4.view.KeyEventDispatcher.activitySuperDispatchKeyEventPre28(KeyEventDispatcher.java:137)
      at android.support.v4.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:87)
      at android.support.v4.app.SupportActivity.dispatchKeyEvent(ComponentActivity.java:126)
      at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:535)
      at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
      at android.support.v7.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:2533)
      at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:357)
      at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4798)
      at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4670)
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4205)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4258)
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4224)
      at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4351)
      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4232)
      at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4408)
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4205)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4258)
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4224)
      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4232)
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4205)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4258)
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4224)
      at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4384)
      at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4552)
      at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2454)
      at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2017)
      at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2008)
      at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2431)
      at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
      at android.os.MessageQueue.nativePollOnce(Native Method)
      at android.os.MessageQueue.next(MessageQueue.java:325)
      at android.os.Looper.loop(Looper.java:142)
      at android.app.ActivityThread.main(ActivityThread.java:6650)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)
  </code></pre>
  <p>I do not know where to put my file if you just write the code.
  I would appreciate it if you write the file name together!</p>