vue-router在ie9及以下history模式支持


參考:

  https://www.npmjs.com/package/vue-route

  https://github.com/devote/HTML5-History-API

 

提要:

  ie9及以下不支持html5 history新特性

 

解決:

  • npm install html5-history-api
  • <!--[if lte IE 9]><script src=“path_to_history.js"></script><![endif]-->
    • issus
      • history.js - IE8+ and other browsers

        history.ielte7.js - IE6+ and other browsers          

      • 使用webpack時 
         1  1 var supportsPushState = inBrowser && (function () {
         2  2   var ua = window.navigator.userAgent;
         3  3 
         4  4   if (
         5  5     (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
         6  6     ua.indexOf('Mobile Safari') !== -1 &&
         7  7     ua.indexOf('Chrome') === -1 &&
         8  8     ua.indexOf('Windows Phone') === -1
         9  9   ) {
        10 10     return false
        11 11   }
        12 12 
        13 13   return window.history && 'pushState' in window.history
        14 14 })();

        這里supportsPushState在加載時已經被定義,就算在之后的 1 require('html5-history-api') 也是沒有意義的,緩存雖然是王道可有時用不好真的是個坑。。。。

         1 var VueRouter = function VueRouter (options) {
         2   if ( options === void 0 ) options = {};
         3 
         4   this.app = null;
         5   this.apps = [];
         6   this.options = options;
         7   this.beforeHooks = [];
         8   this.resolveHooks = [];
         9   this.afterHooks = [];
        10   this.matcher = createMatcher(options.routes || [], this);
        11 
        12   var mode = options.mode || 'hash';
        13   this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false; //這里直接使用了定義好的supportsPushState
        14 
        15   if (this.fallback) { //最終還是使用了hash模式
        16     mode = 'hash';
        17   }
        18   if (!inBrowser) {
        19     mode = 'abstract';
        20   }
        21   this.mode = mode;
        22   switch (mode) {
        23     case 'history':
        24       this.history = new HTML5History(this, options.base);
        25       break
        26     case 'hash':
        27       this.history = new HashHistory(this, options.base, this.fallback);
        28       break
        29     case 'abstract':
        30       this.history = new AbstractHistory(this, options.base);
        31       break
        32     default:
        33       {
        34         assert(false, ("invalid mode: " + mode));
        35       }
        36   }
        37 };  

#在設計緩存時一定要考慮到上下文的依賴,過時的緩存有啥用呢

end

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM