Dogstudio / highway

Highway - A Modern Javascript Transitions Manager
https://highway.js.org/
MIT License
1.43k stars 92 forks source link

ENHANCEMENT: Cordova support (and solution... Not tested in IOS) #93

Closed jose-von-chong closed 4 years ago

jose-von-chong commented 4 years ago

Hi! For anyone trying to make this library work on cordova/ionic/phonegap: I monkey patched the core script so it uses XMLHttpRequest instead of fetch. This makes it compatible with an android build. cleaner code on https://pastebin.pl/view/f40271e2

    let location = this.location.href;
    return new Promise(function (resolve, reject) {
      let xhr = new XMLHttpRequest();
      xhr.open("GET", location);
      xhr.setRequestHeader("X-Requested-With", "Hightway");
      xhr.withCredentials = true;
      xhr.onreadystatechange = function () {
        // Only run if the request is complete
        // Process our return data
        if (xhr.readyState === 4) {
          if (xhr.status == 200) {
            // or xhr.status >= 200 && xhr.status < 300
            resolve(xhr.responseText);
          } else {
            reject("false");
          }
        }
      };
      xhr.send();
    });
  }
  async fetch() {
    return this.xhr_fetch();
  }
Anthodpnt commented 4 years ago

Thanks @jose-von-chong!