/** * vue-router v2.0.0 * (c) 2016 Evan You * @license MIT */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if("/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i=0&&(e=t.slice(r),t=t.slice(0,r));var o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}function n(t){return t.replace(/\/\//g,"/")}function r(t,e){if(!t)throw new Error("[vue-router] "+e)}function o(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function i(t,e){if(void 0===e&&(e={}),t){var n;try{n=a(t)}catch(t){o(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function a(t){var e=Object.create(null);return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=ut(n.shift()),o=n.length>0?ut(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return at(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(at(e)):r.push(at(e)+"="+at(t)))}),r.join("&")}return at(e)+"="+at(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function c(t,e,n){var r={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:p(e),matched:t?s(t):[]};return n&&(r.redirectedFrom=p(n)),Object.freeze(r)}function s(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function p(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+u(n)+r}function f(t,e){return e===ct?t===e:!!e&&(t.path&&e.path?t.path.replace(st,"")===e.path.replace(st,"")&&t.hash===e.hash&&h(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&h(t.query,e.query)&&h(t.params,e.params)))}function h(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function l(t,e){return 0===t.path.indexOf(e.path)&&(!e.hash||t.hash===e.hash)&&d(t.query,e.query)}function d(t,e){for(var n in e)if(!(n in t))return!1;return!0}function y(n,r,o){var a="string"==typeof n?{path:n}:n;if(a.name||a._normalized)return a;var u=e(a.path||""),c=r&&r.path||"/",s=u.path?t(u.path,c,o):r&&r.path||"/",p=i(u.query,a.query),f=a.hash||u.hash;return f&&"#"!==f.charAt(0)&&(f="#"+f),{_normalized:!0,path:s,query:p,hash:f}}function v(t){if(t)for(var e,n=0;n=t.length?n():t[o]?e(t[o],function(){r(o+1)}):r(o+1)};r(0)}function I(t){if(!t)if(kt){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function M(t,e){var n,r=Math.max(t.length,e.length);for(n=0;n=0?e:0)+"#"+t)}var it={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,u=o._routerViewCache||(o._routerViewCache={}),c=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&c++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=c;var p=a.matched[c];if(!p)return t();var f=s?u[n.name]:u[n.name]=p.components[n.name];return s||((i.hook||(i.hook={})).init=function(t){p.instances[n.name]=t.child}),t(f,i,r)}},at=encodeURIComponent,ut=decodeURIComponent,ct=c(null,{path:"/"}),st=/\/$/,pt=[String,Object],ft={name:"router-link",props:{to:{type:pt,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,r=this.$router,o=this.$route,i=y(this.to,o,this.append),a=r.match(i),u=a.redirectedFrom||a.fullPath,s=r.history.base,p=s?n(s+u):u,h={},d=this.activeClass||r.options.linkActiveClass||"router-link-active",m=i.path?c(null,i):a;h[d]=this.exact?f(o,m):l(o,m);var g={click:function(t){t.preventDefault(),e.replace?r.replace(i):r.push(i)}},w={class:h};if("a"===this.tag)w.on=g,w.attrs={href:p};else{var b=v(this.$slots.default);if(b){var x=b.data||(b.data={});x.on=g;var k=x.attrs||(x.attrs={});k.href=p}}return t(this.tag,w,this.$slots.default)}},ht=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},lt=ht,dt=T,yt=g,vt=w,mt=k,gt=_,wt=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");dt.parse=yt,dt.compile=vt,dt.tokensToFunction=mt,dt.tokensToRegExp=gt;var bt=Object.create(null),xt=Object.create(null),kt="undefined"!=typeof window,Ot=kt&&function(){var t=window.navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history)}(),Et=function(t,e){this.router=t,this.base=I(e),this.current=ct,this.pending=null};Et.prototype.listen=function(t){this.cb=t},Et.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r),n.ensureURL()})},Et.prototype.confirmTransition=function(t,e){var n=this,r=this.current;if(f(t,r))return void this.ensureURL();var o=M(this.current.matched,t.matched),i=o.deactivated,a=o.activated,u=[].concat(z(i),this.router.beforeHooks,a.map(function(t){return t.beforeEnter}),J(a));this.pending=t;var c=function(e,o){n.pending===t&&e(t,r,function(t){t===!1?n.ensureURL():"string"==typeof t||"object"==typeof t?n.push(t):o(t)})};H(u,c,function(){var r=[];H(F(a,r),c,function(){n.pending===t&&(n.pending=null,e(t),n.router.app.$nextTick(function(){r.forEach(function(t){return t()})}))})})},Et.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(n){n&&n(t,e)})};var Rt=function(){return String(Date.now())},jt=Rt(),St=function(t){function e(e,n){var r=this;t.call(this,e,n),this.transitionTo(Q(this.base));var o=e.options.scrollBehavior;window.addEventListener("popstate",function(t){jt=t.state&&t.state.key;var e=r.current;r.transitionTo(Q(r.base),function(t){o&&r.handleScroll(t,e,!0)})}),o&&window.addEventListener("scroll",function(){D(jt)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){Z(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.replace=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){tt(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.ensureURL=function(){Q(this.base)!==this.current.fullPath&&tt(n(this.base+this.current.fullPath))},e.prototype.handleScroll=function(t,e,n){var o=this.router;if(o.app){var i=o.options.scrollBehavior;i&&(r("function"==typeof i,"scrollBehavior must be a function"),o.app.$nextTick(function(){var r=X(jt),o=i(t,e,n?r:null);if(o){var a="object"==typeof o;if(a&&"string"==typeof o.selector){var u=document.querySelector(o.selector);u?r=Y(u):W(o)&&(r=G(o))}else a&&W(o)&&(r=G(o));r&&window.scrollTo(r.x,r.y)}}))}},e}(Et),$t=function(t){function e(e,n,r){var o=this;t.call(this,e,n),r&&this.checkFallback()||(et(),this.transitionTo(nt()),window.addEventListener("hashchange",function(){o.onHashChange()}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkFallback=function(){var t=Q(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.onHashChange=function(){et()&&this.transitionTo(nt(),function(t){ot(t.fullPath)})},e.prototype.push=function(e){t.prototype.transitionTo.call(this,e,function(t){rt(t.fullPath)})},e.prototype.replace=function(e){t.prototype.transitionTo.call(this,e,function(t){ot(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(){nt()!==this.current.fullPath&&ot(this.current.fullPath)},e}(Et),At=function(t){function e(e){t.call(this,e),this.stack=[],this.index=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++})},e.prototype.replace=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e.prototype.ensureURL=function(){},e}(Et),_t=function(t){void 0===t&&(t={}),this.app=null,this.options=t,this.beforeHooks=[],this.afterHooks=[],this.match=U(t.routes||[]);var e=t.mode||"hash";this.fallback="history"===e&&!Ot,this.fallback&&(e="hash"),kt||(e="abstract"),this.mode=e},Tt={currentRoute:{}};return Tt.currentRoute.get=function(){return this.history&&this.history.current},_t.prototype.init=function(t){var e=this;r(m.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before creating root instance."),this.app=t;var n=this,o=n.mode,i=n.options,a=n.fallback;switch(o){case"history":this.history=new St(this,i.base);break;case"hash":this.history=new $t(this,i.base,a);break;case"abstract":this.history=new At(this);break;default:r(!1,"invalid mode: "+o)}this.history.listen(function(t){e.app._route=t})},_t.prototype.beforeEach=function(t){this.beforeHooks.push(t)},_t.prototype.afterEach=function(t){this.afterHooks.push(t)},_t.prototype.push=function(t){this.history.push(t)},_t.prototype.replace=function(t){this.history.replace(t)},_t.prototype.go=function(t){this.history.go(t)},_t.prototype.back=function(){this.go(-1)},_t.prototype.forward=function(){this.go(1)},_t.prototype.getMatchedComponents=function(){return this.currentRoute?[].concat.apply([],this.currentRoute.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Object.defineProperties(_t.prototype,Tt),_t.install=m,kt&&window.Vue&&window.Vue.use(_t),_t});