I'm using angular7 preprendered with cordova 9.

All the navigation works fine, but when I try to use location.back() with the router, the url goes outside www and sometimes even crashes the app by going to an invalid url.

The same thing happens sometimes when using the device back button.

Any idea on which can be the problem?

2 Answers

0
MazarD On Best Solutions

I found the solution in an issue on their github. It looks like cordova overwrites the EventTarget causing the problem.

Placing the following code just before cordova.js solved it:

  <script>
      window.addEventListener = function () {
        (window.EventTarget || Window).prototype.addEventListener.apply(this, arguments);
      };
      window.removeEventListener = function () {
        (window.EventTarget || Window).prototype.removeEventListener.apply(this, arguments);
      };
      document.addEventListener = function () {
        (window.EventTarget || Document).prototype.addEventListener.apply(this, arguments);
      };
      document.removeEventListener = function () {
        (window.EventTarget || Document).prototype.removeEventListener.apply(this, arguments);
      };
  </script>  
  <script type="text/javascript" src="cordova.js"></script>
0
Baruch G. On