与cordova成角度的location.back路由问题

Maz*_*arD 2 cordova angular

我正在使用使用cordova 9预渲染的angular7。

所有导航都工作正常,但是当我尝试location.back()与路由器一起使用时,该 url 超出 www 并且有时甚至通过转到invalid url.

使用设备后退按钮时有时会发生同样的事情。

任何想法可能是问题?

Maz*_*arD 6

我在他们 github 上的一个问题中找到了解决方案。看起来cordova覆盖了导致问题的EventTarget。

在cordova.js解决它之前放置以下代码:

  <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>
Run Code Online (Sandbox Code Playgroud)

  • 可以确认这适用于 iOS 和 Android。Angular 版本:11.2.4、Cordova 版本 10.0.0、iOS(平台)版本 6.2.0、Android(平台)版本 9。 (2认同)