function Router(routes) { try { if (!routes) { throw 'error: routes param is mandatory'; } this.constructor(routes); this.init(); } catch (e) { console.error(e); } } Router.prototype = { routes: undefined, rootElem: undefined, constructor: function (routes) { this.routes = routes; this.rootElem = document.getElementById('app'); }, init: function () { var r = this.routes; (function(scope, r) { window.addEventListener('hashchange', function (e) { scope.hasChanged(scope, r); }); })(this, r); this.hasChanged(this, r); }, hasChanged: function(scope, r){ if (window.location.hash.length > 0) { for (var i = 0, length = r.length; i < length; i++) { var route = r[i]; ///CUSTOM// REMOVE PARAM// var curent_hash=window.location.hash.substr(1); var _hash=curent_hash.split("?"); // alert(window.location.hash.substr(1)) if(route.isActiveRoute(_hash[0])) { scope.goToRoute(route.htmlName); } } } else { for (var i = 0, length = r.length; i < length; i++) { var route = r[i]; if(route.default) { scope.goToRoute(route.htmlName); } } } }, goToRoute: function (htmlName) { (function(scope) { if(htmlName==""){ } var param=""; var winurl=window.location.hash.substr(1); var getpara=winurl.split('?'); if(getpara[1]!==""&&getpara[1]!=undefined){ param="?"+getpara[1] } // console.log('https://m.asiawin.cc/'+url+'/'+param); var url = htmlName, xhttp = new XMLHttpRequest(); var domain = window.location.hostname; xhttp.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { scope.rootElem.innerHTML = this.responseText; var scripts = scope.rootElem.getElementsByTagName('script'); for (var ix = 0; ix < scripts.length; ix++) { eval(scripts[ix].text); } } }; // xhttp.open('GET', 'https://m.asiawin.cc/'+url+'/'+param, true); xhttp.open('GET', 'https://'+domain+'/'+url+'/'+param, true); xhttp.send(); })(this); } };