vue-router
Advanced tools
Comparing version 0.7.0 to 0.7.1
/*! | ||
* vue-router v0.7.0 | ||
* vue-router v0.7.1 | ||
* (c) 2015 Evan You | ||
* Released under the MIT License. | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueRouter=e():t.VueRouter=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var a=n[r]={exports:{},id:r,loaded:!1};return t[r].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t,e){var n=e.component;$.util.isPlainObject(n)&&(n=e.component=$.extend(n)),"function"!=typeof n&&(e.component=null,s.warn('invalid component for route "'+t+'".'))}var a=n(1)["default"],o=n(5)["default"],i=n(6)["default"];Object.defineProperty(e,"__esModule",{value:!0});var s=n(7),u=i(s),c=n(11),h=i(c),l=n(8),f=i(l),d=n(12),p=i(d),v=n(22),g=i(v),y=n(29),m=i(y),_=n(30),w=i(_),b=n(31),x=i(b),C=n(32),k=i(C),P=n(33),R=i(P),E={"abstract":x["default"],hash:k["default"],html5:R["default"]},$=void 0,O=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.hashbang,r=void 0===n?!0:n,a=e["abstract"],i=void 0===a?!1:a,s=e.history,u=void 0===s?!1:s,c=e.saveScrollPosition,h=void 0===c?!1:c,l=e.transitionOnLoad,d=void 0===l?!1:l,p=e.suppressTransitionError,v=void 0===p?!1:p,g=e.root,y=void 0===g?null:g,m=e.linkActiveClass,_=void 0===m?"v-link-active":m;if(o(this,t),!t.installed)throw new Error("Please install the Router with Vue.use() before creating an instance.");this.app=null,this._views=[],this._children=[],this._recognizer=new f["default"],this._guardRecognizer=new f["default"],this._started=!1,this._startCb=null,this._currentRoute={},this._currentTransition=null,this._previousTransition=null,this._notFoundHandler=null,this._beforeEachHooks=[],this._afterEachHooks=[],this._hasPushState="undefined"!=typeof window&&window.history&&window.history.pushState,this._rendered=!1,this._transitionOnLoad=d,this._abstract=i,this._hashbang=r,this._history=this._hasPushState&&u,this._saveScrollPosition=h,this._linkActiveClass=_,this._suppress=v;var w=$.util.inBrowser;this.mode=!w||this._abstract?"abstract":this._history?"html5":"hash";var b=E[this.mode],x=this;this.history=new b({root:y,hashbang:this._hashbang,onChange:function(t,e,n){x._match(t,e,n)}})}return a(t,[{key:"map",value:function(t){for(var e in t)this.on(e,t[e])}},{key:"on",value:function(t,e){"*"===t?this._notFound(e):this._addRoute(t,e,[])}},{key:"redirect",value:function(t){for(var e in t)this._addRedirect(e,t[e])}},{key:"alias",value:function(t){for(var e in t)this._addAlias(e,t[e])}},{key:"beforeEach",value:function(t){this._beforeEachHooks.push(t)}},{key:"afterEach",value:function(t){this._afterEachHooks.push(t)}},{key:"go",value:function(t){var e=!1,n=!1;$.util.isObject(t)&&(e=t.replace,n=t.append),t=this._stringifyPath(t),this.history.go(t,e,n)}},{key:"replace",value:function(t){this.go({path:t,replace:!0})}},{key:"start",value:function(t,e,n){if(this._started)return void s.warn("already started.");if(this._started=!0,this._startCb=n,!this.app){if(!t||!e)throw new Error("Must start vue-router with a component and a root container.");this._appContainer=e,this._appConstructor="function"==typeof t?t:$.extend(t)}this.history.start()}},{key:"stop",value:function(){this.history.stop(),this._started=!1}},{key:"_addRoute",value:function(t,e,n){if(r(t,e),e.path=t,e.fullPath=(n.reduce(function(t,e){return t+e.path},"")+t).replace("//","/"),n.push({path:t,handler:e}),this._recognizer.add(n,{as:e.name}),e.subRoutes)for(var a in e.subRoutes)this._addRoute(a,e.subRoutes[a],n.slice())}},{key:"_notFound",value:function(t){r("*",t),this._notFoundHandler=[{handler:t}]}},{key:"_addRedirect",value:function(t,e){this._addGuard(t,e,this.replace)}},{key:"_addAlias",value:function(t,e){this._addGuard(t,e,this._match)}},{key:"_addGuard",value:function(t,e,n){var r=this;this._guardRecognizer.add([{path:t,handler:function(t,a){var o=s.mapParams(e,t.params,a);n.call(r,o)}}])}},{key:"_checkGuard",value:function(t){var e=this._guardRecognizer.recognize(t);return e?(e[0].handler(e[0],e.queryParams),!0):void 0}},{key:"_match",value:function(t,e,n){var r=this;if(!this._checkGuard(t)){var a=this._currentRoute,o=this._currentTransition;if(!o||t!==a.path){var i=new p["default"](t,this),s=new g["default"](this,i,a);this._prevTransition=o,this._currentTransition=s,this.app||(this.app=new this._appConstructor({el:this._appContainer,_meta:{$route:i}}));var u=this._beforeEachHooks,c=function(){s.start(function(){r._postTransition(i,e,n)})};u.length?s.runQueue(u,function(t,e,n){s===r._currentTransition&&s.callHook(t,null,n,!0)},c):c(),!this._rendered&&this._startCb&&this._startCb.call(null),this._rendered=!0}}}},{key:"_onTransitionValidated",value:function(t){var e=this._prevTransition;e&&(e.aborted=!0);var n=this._currentRoute=t.to;this.app.$route!==n&&(this.app.$route=n,this._children.forEach(function(t){t.$route=n})),this._afterEachHooks.length&&this._afterEachHooks.forEach(function(e){return e.call(null,{to:t.to,from:t.from})}),this._currentTransition.done=!0}},{key:"_postTransition",value:function(t,e,n){var r=e&&e.pos;r&&this._saveScrollPosition?$.nextTick(function(){window.scrollTo(r.x,r.y)}):n&&$.nextTick(function(){var t=document.getElementById(n.slice(1));t&&window.scrollTo(window.scrollX,t.offsetTop)})}},{key:"_stringifyPath",value:function(t){if("object"==typeof t){if(t.name){var e=t.params||{};return t.query&&(e.queryParams=t.query),this._recognizer.generate(t.name,e)}return t.path?t.path:""}return t+""}}]),t}();O.installed=!1,O.install=function(t){if(O.installed)return void s.warn("already installed.");$=t,h["default"]($),m["default"]($),w["default"]($),u["default"].Vue=$;var e=$.config.optionMergeStrategies;e&&(e.route=e.methods),O.installed=!0},"undefined"!=typeof window&&window.Vue&&window.Vue.use(O),e["default"]=O,t.exports=e["default"]},function(t,e,n){"use strict";var r=n(2)["default"];e["default"]=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),r(t,a.key,a)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),e.__esModule=!0},function(t,e,n){t.exports={"default":n(3),__esModule:!0}},function(t,e,n){var r=n(4);t.exports=function(t,e,n){return r.setDesc(t,e,n)}},function(t,e){var n=Object;t.exports={create:n.create,getProto:n.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:n.getOwnPropertyDescriptor,setDesc:n.defineProperty,setDescs:n.defineProperties,getKeys:n.keys,getNames:n.getOwnPropertyNames,getSymbols:n.getOwnPropertySymbols,each:[].forEach}},function(t,e){"use strict";e["default"]=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e.__esModule=!0},function(t,e){"use strict";e["default"]=function(t){return t&&t.__esModule?t:{"default":t}},e.__esModule=!0},function(t,e,n){"use strict";function r(t){window.console&&(console.warn("[vue-router] "+t),(!d.Vue||d.Vue.config.debug)&&console.warn(new Error("warning stack trace:").stack))}function a(t,e,n){var r=t.match(/(\?.*)$/);if(r&&(r=r[1],t=t.slice(0,-r.length)),"?"===e.charAt(0))return t+e;var a=t.split("/");n&&a[a.length-1]||a.pop();for(var o=e.replace(/^\//,"").split("/"),i=0;i<o.length;i++){var s=o[i];"."!==s&&(".."===s?a.pop():a.push(s))}return""!==a[0]&&a.unshift(""),a.join("/")}function o(t){return t&&"function"==typeof t.then}function i(t,e){var n=t&&(t.$options||t.options);return n&&n.route&&n.route[e]}function s(t,e){p?p.$options.components._=t.component:p={resolve:d.Vue.prototype._resolveComponent,$options:{components:{_:t.component}}},p.resolve("_",function(n){t.component=n,e(n)})}function u(t,e,n){return void 0===e&&(e={}),t=t.replace(/:([^\/]+)/g,function(n,a){var o=e[a];return o||r('param "'+a+'" not found when generating path for "'+t+'" with params '+JSON.stringify(e)),o||""}),n&&(t+=f(n)),t}var c=n(6)["default"];Object.defineProperty(e,"__esModule",{value:!0}),e.warn=r,e.resolvePath=a,e.isPromise=o,e.getRouteConfig=i,e.resolveAsyncComponent=s,e.mapParams=u;var h=n(8),l=c(h),f=l["default"].prototype.generateQueryString,d={};e["default"]=d;var p=void 0},function(t,e,n){var r;(function(t){(function(){"use strict";function a(t,e,n){this.path=t,this.matcher=e,this.delegate=n}function o(t){this.routes={},this.children={},this.target=t}function i(t,e,n){return function(r,o){var s=t+r;return o?void o(i(s,e,n)):new a(t+r,e,n)}}function s(t,e,n){for(var r=0,a=0,o=t.length;o>a;a++)r+=t[a].path.length;e=e.substr(r);var i={path:e,handler:n};t.push(i)}function u(t,e,n,r){var a=e.routes;for(var o in a)if(a.hasOwnProperty(o)){var i=t.slice();s(i,o,a[o]),e.children[o]?u(i,e.children[o],n,r):n.call(r,i)}}function c(t){return"[object Array]"===Object.prototype.toString.call(t)}function h(t){this.string=t}function l(t){this.name=t}function f(t){this.name=t}function d(){}function p(t,e,n){"/"===t.charAt(0)&&(t=t.substr(1));var r=t.split("/"),a=[];n.val="";for(var o=0,i=r.length;i>o;o++){var s,u=r[o];(s=u.match(/^:([^\/]+)$/))?(a.push(new l(s[1])),e.push(s[1]),n.val+="3"):(s=u.match(/^\*([^\/]+)$/))?(a.push(new f(s[1])),n.val+="2",e.push(s[1])):""===u?(a.push(new d),n.val+="1"):(a.push(new h(u)),n.val+="4")}return n.val=+n.val,a}function v(t){this.charSpec=t,this.nextStates=[]}function g(t){return t.sort(function(t,e){return e.specificity.val-t.specificity.val})}function y(t,e){for(var n=[],r=0,a=t.length;a>r;r++){var o=t[r];n=n.concat(o.match(e))}return n}function m(t){this.queryParams=t||{}}function _(t,e,n){for(var r=t.handlers,a=t.regex,o=e.match(a),i=1,s=new m(n),u=0,c=r.length;c>u;u++){for(var h=r[u],l=h.names,f={},d=0,p=l.length;p>d;d++)f[l[d]]=o[i++];s.push({handler:h.handler,params:f,isDynamic:!!l.length})}return s}function w(t,e){return e.eachChar(function(e){t=t.put(e)}),t}function b(t){return t=t.replace(/\+/gm,"%20"),decodeURIComponent(t)}a.prototype={to:function(t,e){var n=this.delegate;if(n&&n.willAddRoute&&(t=n.willAddRoute(this.matcher.target,t)),this.matcher.add(this.path,t),e){if(0===e.length)throw new Error("You must have an argument in the function passed to `to`");this.matcher.addChild(this.path,t,e,this.delegate)}return this}},o.prototype={add:function(t,e){this.routes[t]=e},addChild:function(t,e,n,r){var a=new o(e);this.children[t]=a;var s=i(t,a,r);r&&r.contextEntered&&r.contextEntered(e,s),n(s)}};var x=function(t,e){var n=new o;t(i("",n,this.delegate)),u([],n,function(t){e?e(this,t):this.add(t)},this)},C=["/",".","*","+","?","|","(",")","[","]","{","}","\\"],k=new RegExp("(\\"+C.join("|\\")+")","g");h.prototype={eachChar:function(t){for(var e,n=this.string,r=0,a=n.length;a>r;r++)e=n.charAt(r),t({validChars:e})},regex:function(){return this.string.replace(k,"\\$1")},generate:function(){return this.string}},l.prototype={eachChar:function(t){t({invalidChars:"/",repeat:!0})},regex:function(){return"([^/]+)"},generate:function(t){return t[this.name]}},f.prototype={eachChar:function(t){t({invalidChars:"",repeat:!0})},regex:function(){return"(.+)"},generate:function(t){return t[this.name]}},d.prototype={eachChar:function(){},regex:function(){return""},generate:function(){return""}},v.prototype={get:function(t){for(var e=this.nextStates,n=0,r=e.length;r>n;n++){var a=e[n],o=a.charSpec.validChars===t.validChars;if(o=o&&a.charSpec.invalidChars===t.invalidChars)return a}},put:function(t){var e;return(e=this.get(t))?e:(e=new v(t),this.nextStates.push(e),t.repeat&&e.nextStates.push(e),e)},match:function(t){for(var e,n,r,a=this.nextStates,o=[],i=0,s=a.length;s>i;i++)e=a[i],n=e.charSpec,"undefined"!=typeof(r=n.validChars)?-1!==r.indexOf(t)&&o.push(e):"undefined"!=typeof(r=n.invalidChars)&&-1===r.indexOf(t)&&o.push(e);return o}};var P=Object.create||function(t){function e(){}return e.prototype=t,new e};m.prototype=P({splice:Array.prototype.splice,slice:Array.prototype.slice,push:Array.prototype.push,length:0,queryParams:null});var R=function(){this.rootState=new v,this.names={}};R.prototype={add:function(t,e){for(var n,r=this.rootState,a="^",o={},i=[],s=[],u=!0,c=0,h=t.length;h>c;c++){var l=t[c],f=[],v=p(l.path,f,o);s=s.concat(v);for(var g=0,y=v.length;y>g;g++){var m=v[g];m instanceof d||(u=!1,r=r.put({validChars:"/"}),a+="/",r=w(r,m),a+=m.regex())}var _={handler:l.handler,names:f};i.push(_)}u&&(r=r.put({validChars:"/"}),a+="/"),r.handlers=i,r.regex=new RegExp(a+"$"),r.specificity=o,(n=e&&e.as)&&(this.names[n]={segments:s,handlers:i})},handlersFor:function(t){var e=this.names[t],n=[];if(!e)throw new Error("There is no route named "+t);for(var r=0,a=e.handlers.length;a>r;r++)n.push(e.handlers[r]);return n},hasRoute:function(t){return!!this.names[t]},generate:function(t,e){var n=this.names[t],r="";if(!n)throw new Error("There is no route named "+t);for(var a=n.segments,o=0,i=a.length;i>o;o++){var s=a[o];s instanceof d||(r+="/",r+=s.generate(e))}return"/"!==r.charAt(0)&&(r="/"+r),e&&e.queryParams&&(r+=this.generateQueryString(e.queryParams,n.handlers)),r},generateQueryString:function(t,e){var n=[],r=[];for(var a in t)t.hasOwnProperty(a)&&r.push(a);r.sort();for(var o=0,i=r.length;i>o;o++){a=r[o];var s=t[a];if(null!=s){var u=encodeURIComponent(a);if(c(s))for(var h=0,l=s.length;l>h;h++){var f=a+"[]="+encodeURIComponent(s[h]);n.push(f)}else u+="="+encodeURIComponent(s),n.push(u)}}return 0===n.length?"":"?"+n.join("&")},parseQueryString:function(t){for(var e=t.split("&"),n={},r=0;r<e.length;r++){var a,o=e[r].split("="),i=b(o[0]),s=i.length,u=!1;1===o.length?a="true":(s>2&&"[]"===i.slice(s-2)&&(u=!0,i=i.slice(0,s-2),n[i]||(n[i]=[])),a=o[1]?b(o[1]):""),u?n[i].push(a):n[i]=a}return n},recognize:function(t){var e,n,r,a,o=[this.rootState],i={},s=!1;if(a=t.indexOf("?"),-1!==a){var u=t.substr(a+1,t.length);t=t.substr(0,a),i=this.parseQueryString(u)}for(t=decodeURI(t),"/"!==t.charAt(0)&&(t="/"+t),e=t.length,e>1&&"/"===t.charAt(e-1)&&(t=t.substr(0,e-1),s=!0),n=0,r=t.length;r>n&&(o=y(o,t.charAt(n)),o.length);n++);var c=[];for(n=0,r=o.length;r>n;n++)o[n].handlers&&c.push(o[n]);o=g(c);var h=c[0];return h&&h.handlers?(s&&"(.+)$"===h.regex.source.slice(-5)&&(t+="/"),_(h,t,i)):void 0}},R.prototype.map=x,R.VERSION="0.1.9";var E=R;n(10).amd?(r=function(){return E}.call(e,n,e,t),!(void 0!==r&&(t.exports=r))):"undefined"!=typeof t&&t.exports?t.exports=E:"undefined"!=typeof this&&(this.RouteRecognizer=E)}).call(this)}).call(e,n(9)(t))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e){t.exports=function(){throw new Error("define cannot be used indirect")}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=function(t){var e=t.util,n={created:function(){var t=this.$root.$route;t&&(t.router._children.push(this),this.$route||(this._defineMeta?this._defineMeta("$route",t):e.defineReactive(this,"$route",t)))},beforeDestroy:function(){var t=this.$root.$route;t&&t.router._children.$remove(this)}};t.mixin?t.mixin(n):t.options=e.mergeOptions(t.options,n)},t.exports=e["default"]},function(t,e,n){"use strict";var r=n(5)["default"],a=n(13)["default"];Object.defineProperty(e,"__esModule",{value:!0});var o=/^(component|subRoutes)$/,i=function s(t,e){var n=this;r(this,s);var i=e._recognizer.recognize(t);i&&([].forEach.call(i,function(t){for(var e in t.handler)o.test(e)||(n[e]=t.handler[e])}),this.query=i.queryParams,this.params=[].reduce.call(i,function(t,e){if(e.params)for(var n in e.params)t[n]=e.params[n];return t},{})),this.path=t,this.router=e,this.matched=i||e._notFoundHandler,a(this)};e["default"]=i,t.exports=e["default"]},function(t,e,n){t.exports={"default":n(14),__esModule:!0}},function(t,e,n){n(15),t.exports=n(20).Object.freeze},function(t,e,n){var r=n(16);n(17)("freeze",function(t){return function(e){return t&&r(e)?t(e):e}})},function(t,e){t.exports=function(t){return null!==t&&("object"==typeof t||"function"==typeof t)}},function(t,e,n){t.exports=function(t,e){var r=n(18),a=(n(20).Object||{})[t]||Object[t],o={};o[t]=e(a),r(r.S+r.F*n(21)(function(){a(1)}),"Object",o)}},function(t,e,n){var r=n(19),a=n(20),o="prototype",i=function(t,e){return function(){return t.apply(e,arguments)}},s=function(t,e,n){var u,c,h,l,f=t&s.G,d=t&s.P,p=f?r:t&s.S?r[e]:(r[e]||{})[o],v=f?a:a[e]||(a[e]={});f&&(n=e);for(u in n)c=!(t&s.F)&&p&&u in p,c&&u in v||(h=c?p[u]:n[u],f&&"function"!=typeof p[u]?l=n[u]:t&s.B&&c?l=i(h,r):t&s.W&&p[u]==h?!function(t){l=function(e){return this instanceof t?new t(e):t(e)},l[o]=t[o]}(h):l=d&&"function"==typeof h?i(Function.call,h):h,v[u]=l,d&&((v[o]||(v[o]={}))[u]=h))};s.F=1,s.G=2,s.S=4,s.P=8,s.B=16,s.W=32,t.exports=s},function(t,e){var n="undefined",r=t.exports=typeof window!=n&&window.Math==Math?window:typeof self!=n&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},function(t,e){var n=t.exports={};"number"==typeof __e&&(__e=n)},function(t,e){t.exports=function(t){try{return!!t()}catch(e){return!0}}},function(t,e,n){"use strict";function r(t){return"[object Object]"===Object.prototype.toString.call(t)}var a=n(1)["default"],o=n(5)["default"];Object.defineProperty(e,"__esModule",{value:!0});var i=n(7),s=n(23),u=function(){function t(e,n,r){o(this,t),this.router=e,this.to=n,this.from=r,this.next=null,this.aborted=!1,this.done=!1,this.deactivateQueue=e._views;var a=n.matched?Array.prototype.slice.call(n.matched):[];this.activateQueue=a.map(function(t){return t.handler})}return a(t,[{key:"abort",value:function(){if(!this.aborted){this.aborted=!0;var t=!this.from.path&&"/"===this.to.path;t||this.router.replace(this.from.path||"/")}}},{key:"redirect",value:function(t){this.aborted||(this.aborted=!0,"string"==typeof t?t=i.mapParams(t,this.to.params,this.to.query):(t.params=this.to.params,t.query=this.to.query),this.router.replace(t))}},{key:"start",value:function(t){var e=this,n=this.deactivateQueue,r=this.activateQueue,a=n.slice().reverse(),o=void 0,i=void 0;for(i=0;i<a.length&&s.canReuse(a[i],r[i],e);i++);i>0&&(o=a.slice(0,i),n=a.slice(i).reverse(),r=r.slice(i)),e.runQueue(n,s.canDeactivate,function(){e.runQueue(r,s.canActivate,function(){e.runQueue(n,s.deactivate,function(){if(e.router._onTransitionValidated(e),o&&o.forEach(function(t){s.reuse(t,e)}),n.length){var r=n[n.length-1],a=o?o.length:0;s.activate(r,e,a,t)}else t()})})})}},{key:"runQueue",value:function(t,e,n){function r(o){o>=t.length?n():e(t[o],a,function(){r(o+1)})}var a=this;r(0)}},{key:"callHook",value:function(t,e,n){var a=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],o=a.expectBoolean,s=void 0===o?!1:o,u=a.expectData,c=void 0===u?!1:u,h=a.cleanup,l=this,f=!1,d=function(t){h&&h(),l.abort(t)},p=function(t){if(h?v():d(),t&&!l.router._suppress)throw i.warn("Uncaught error during transition: "),t instanceof Error?t:new Error(t)},v=function(t){return f?void i.warn("transition.next() should be called only once."):(f=!0,void(n&&!l.aborted&&n(t,p)))},g={to:l.to,from:l.from,abort:d,next:v,redirect:function(){l.redirect.apply(l,arguments)}},y=void 0;try{y=t.call(e,g)}catch(m){return p(m)}var _=i.isPromise(y);s?"boolean"==typeof y?y?v():d():_&&y.then(function(t){t?v():d()},p):_?y.then(v,p):c&&r(y)&&v(y)}}]),t}();e["default"]=u,t.exports=e["default"]},function(t,e,n){"use strict";function r(t,e,n){var r=t.childVM;if(!r||!e)return!1;if(t.Component!==e.component)return!1;var a=l.getRouteConfig(r,"canReuse");return"boolean"==typeof a?a:a?a.call(r,{to:n.to,from:n.from}):!0}function a(t,e,n){var r=t.childVM,a=l.getRouteConfig(r,"canDeactivate");a?e.callHook(a,r,n,{expectBoolean:!0}):n()}function o(t,e,n){l.resolveAsyncComponent(t,function(t){if(!e.aborted){var r=l.getRouteConfig(t,"canActivate");r?e.callHook(r,null,n,{expectBoolean:!0}):n()}})}function i(t,e,n){var r=t.childVM,a=l.getRouteConfig(r,"deactivate");a?e.callHook(a,r,n):n()}function s(t,n,r,a){var o=n.activateQueue[r];if(!o)return t._bound&&t.setComponent(null),void(a&&a());var i=t.Component=o.component,s=l.getRouteConfig(i,"activate"),u=l.getRouteConfig(i,"data"),h=l.getRouteConfig(i,"waitForData");t.depth=r,t.activated=!1,t.unbuild(!0);var f=t.build({_meta:{$loadingRouteData:!(!u||h)}}),d=function(){f.$destroy()},p=function(){var e=n.router;e._rendered||e._transitionOnLoad?t.transition(f):(t.setCurrent?t.setCurrent(f):t.childVM=f,f.$before(t.anchor,null,!1)),a&&a()},v=function(){t.activated=!0,t.childView&&e.activate(t.childView,n,r+1),u&&h?c(f,n,u,p,d):(u&&c(f,n,u),p())};s?n.callHook(s,f,v,{cleanup:d}):v()}function u(t,e){var n=t.childVM,r=l.getRouteConfig(n,"data");r&&c(n,e,r)}function c(t,e,n,r,a){t.$loadingRouteData=!0,e.callHook(n,t,function(e,n){var a=[];h(e).forEach(function(n){var r=e[n];l.isPromise(r)?a.push(r.then(function(e){t.$set(n,e)})):t.$set(n,r)}),a.length?a[0].constructor.all(a).then(function(e){t.$loadingRouteData=!1},n):t.$loadingRouteData=!1,r&&r(e)},{cleanup:a,expectData:!0})}var h=n(24)["default"];Object.defineProperty(e,"__esModule",{value:!0}),e.canReuse=r,e.canDeactivate=a,e.canActivate=o,e.deactivate=i,e.activate=s,e.reuse=u;var l=n(7)},function(t,e,n){t.exports={"default":n(25),__esModule:!0}},function(t,e,n){n(26),t.exports=n(20).Object.keys},function(t,e,n){var r=n(27);n(17)("keys",function(t){return function(e){return t(r(e))}})},function(t,e,n){var r=n(28);t.exports=function(t){return Object(r(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(7),a=n(23);e["default"]=function(t){var e=t.util,n=t.directive("_component")||t.internalDirectives.component,o=e.extend({},n);e.extend(o,{_isRouterView:!0,bind:function(){var t=this.vm.$route;if(!t)return void r.warn("<router-view> can only be used inside a router-enabled app.");this._isDynamicLiteral=!0,n.bind.call(this),this.keepAlive&&(this.keepAlive=!1,r.warn("<router-view> does not support keep-alive."));var e=this.router=t.router;e._views.unshift(this);var o=e._views[1];o&&(o.childView=this);var i=t.router._currentTransition;if(!o&&i.done||o&&o.activated){var s=o?o.depth+1:0;a.activate(this,i,s)}},unbind:function(){this.router._views.$remove(this),n.unbind.call(this)}}),t.elementDirective("router-view",o)},t.exports=e["default"]},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(7),a=/[-.*+?^${}()|[\]\/\\]/g;e["default"]=function(t){function e(t){return t.protocol===location.protocol&&t.hostname===location.hostname&&t.port===location.port}var n=t.util;t.directive("link",{bind:function(){var t=this,a=this.vm;if(!a.$route)return void r.warn("v-link can only be used inside a router-enabled app.");var o=a.$route.router;this.handler=function(n){if(!(n.metaKey||n.ctrlKey||n.shiftKey||n.defaultPrevented||0!==n.button)){var r=t.target;if("A"===t.el.tagName||n.target===t.el)n.preventDefault(),null!=r&&o.go(r);else{for(var a=n.target;a&&"A"!==a.tagName&&a!==t.el;)a=a.parentNode;if(!a||"A"!==a.tagName||!a.href)return;e(a)&&(n.preventDefault(),o.go({path:a.pathname,replace:r&&r.replace,append:r&&r.append}))}}},this.el.addEventListener("click",this.handler),this.unwatch=a.$watch("$route.path",n.bind(this.updateClasses,this))},update:function(t){var e=this.vm.$route.router,r=void 0;this.target=t,n.isObject(t)&&(r=t.append,this.exact=t.exact,this.prevActiveClass=this.activeClass,this.activeClass=t.activeClass),t=this.path=e._stringifyPath(t),this.activeRE=t&&!this.exact?new RegExp("^"+t.replace(/\/$/,"").replace(a,"\\$&")+"(\\/|$)"):null,this.updateClasses(this.vm.$route.path);var o="/"===t.charAt(0),i="hash"===e.mode||o?e.history.formatPath(t,r):t;"A"===this.el.tagName&&(i?this.el.href=i:this.el.removeAttribute("href"))},updateClasses:function(t){var e=this.el,r=this.path,a=this.vm.$route.router,o=this.activeClass||a._linkActiveClass;this.prevActiveClass!==o&&n.removeClass(e,this.prevActiveClass),this.exact?t===r?n.addClass(e,o):n.removeClass(e,o):this.activeRE&&this.activeRE.test(t)?n.addClass(e,o):n.removeClass(e,o)},unbind:function(){this.el.removeEventListener("click",this.handler),this.unwatch&&this.unwatch()}})},t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"],a=n(5)["default"];Object.defineProperty(e,"__esModule",{value:!0});var o=n(7),i=function(){function t(e){var n=e.onChange;a(this,t),this.onChange=n,this.currentPath="/"}return r(t,[{key:"start",value:function(){this.onChange("/")}},{key:"stop",value:function(){}},{key:"go",value:function(t,e,n){t=this.currentPath=this.formatPath(t,n),this.onChange(t)}},{key:"formatPath",value:function(t,e){return"/"===t.charAt(0)?t:o.resolvePath(this.currentPath,t,e)}}]),t}();e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"],a=n(5)["default"];Object.defineProperty(e,"__esModule",{value:!0});var o=n(7),i=function(){function t(e){var n=e.hashbang,r=e.onChange;a(this,t),this.hashbang=n,this.onChange=r}return r(t,[{key:"start",value:function(){var t=this;this.listener=function(){var e=location.hash,n=e.replace(/^#!?/,"");"/"!==n.charAt(0)&&(n="/"+n);var r=t.formatPath(n);if(r!==e)return void location.replace(r);var a=decodeURI(e.replace(/^#!?/,"")+location.search);t.onChange(a)},window.addEventListener("hashchange",this.listener),this.listener()}},{key:"stop",value:function(){window.removeEventListener("hashchange",this.listener)}},{key:"go",value:function(t,e,n){t=this.formatPath(t,n),e?location.replace(t):location.hash=t}},{key:"formatPath",value:function(t,e){var n="/"===t.charAt(0),r="#"+(this.hashbang?"!":"");return n?r+t:r+o.resolvePath(location.hash.replace(/^#!?/,""),t,e)}}]),t}();e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"],a=n(5)["default"];Object.defineProperty(e,"__esModule",{value:!0});var o=n(7),i=/#.*$/,s=function(){function t(e){var n=e.root,r=e.onChange;a(this,t),n?("/"!==n.charAt(0)&&(n="/"+n),this.root=n.replace(/\/$/,""),this.rootRE=new RegExp("^\\"+this.root)):this.root=null,this.onChange=r;var o=document.querySelector("base");this.base=o&&o.getAttribute("href")}return r(t,[{key:"start",value:function(){var t=this;this.listener=function(e){var n=decodeURI(location.pathname+location.search);t.root&&(n=n.replace(t.rootRE,"")),t.onChange(n,e&&e.state,location.hash)},window.addEventListener("popstate",this.listener),this.listener()}},{key:"stop",value:function(){window.removeEventListener("popstate",this.listener)}},{key:"go",value:function(t,e,n){var r=this.formatPath(t,n);e?history.replaceState({},"",r):(history.replaceState({pos:{x:window.pageXOffset,y:window.pageYOffset}},""),history.pushState({},"",r));var a=t.match(i),o=a&&a[0];t=r.replace(i,"").replace(this.rootRE,""),this.onChange(t,null,o)}},{key:"formatPath",value:function(t,e){return"/"===t.charAt(0)?this.root?this.root+"/"+t.replace(/^\//,""):t:o.resolvePath(this.base||location.pathname,t,e)}}]),t}();e["default"]=s,t.exports=e["default"]}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueRouter=e():t.VueRouter=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t,e){var n=e.component;P.util.isPlainObject(n)&&(n=e.component=P.extend(n)),"function"!=typeof n&&(e.component=null,a.warn('invalid component for route "'+t+'".'))}var o=n(1)["default"],i=n(2)["default"];e.__esModule=!0;var a=n(3),s=i(a),u=n(7),c=i(u),h=n(4),l=i(h),f=n(8),p=i(f),d=n(18),v=i(d),g=n(25),m=i(g),y=n(26),_=i(y),w=n(27),b=i(w),x=n(28),C=i(x),R=n(29),$=i(R),E={"abstract":b["default"],hash:C["default"],html5:$["default"]},P=void 0,A=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.hashbang,r=void 0===n?!0:n,i=e["abstract"],a=void 0===i?!1:i,s=e.history,u=void 0===s?!1:s,c=e.saveScrollPosition,h=void 0===c?!1:c,f=e.transitionOnLoad,p=void 0===f?!1:f,d=e.suppressTransitionError,v=void 0===d?!1:d,g=e.root,m=void 0===g?null:g,y=e.linkActiveClass,_=void 0===y?"v-link-active":y;if(o(this,t),!t.installed)throw new Error("Please install the Router with Vue.use() before creating an instance.");this.app=null,this._views=[],this._children=[],this._recognizer=new l["default"],this._guardRecognizer=new l["default"],this._started=!1,this._startCb=null,this._currentRoute={},this._currentTransition=null,this._previousTransition=null,this._notFoundHandler=null,this._beforeEachHooks=[],this._afterEachHooks=[],this._hasPushState="undefined"!=typeof window&&window.history&&window.history.pushState,this._rendered=!1,this._transitionOnLoad=p,this._abstract=a,this._hashbang=r,this._history=this._hasPushState&&u,this._saveScrollPosition=h,this._linkActiveClass=_,this._suppress=v;var w=P.util.inBrowser;this.mode=!w||this._abstract?"abstract":this._history?"html5":"hash";var b=E[this.mode],x=this;this.history=new b({root:m,hashbang:this._hashbang,onChange:function(t,e,n){x._match(t,e,n)}})}return t.prototype.map=function(t){for(var e in t)this.on(e,t[e])},t.prototype.on=function(t,e){"*"===t?this._notFound(e):this._addRoute(t,e,[])},t.prototype.redirect=function(t){for(var e in t)this._addRedirect(e,t[e])},t.prototype.alias=function(t){for(var e in t)this._addAlias(e,t[e])},t.prototype.beforeEach=function(t){this._beforeEachHooks.push(t)},t.prototype.afterEach=function(t){this._afterEachHooks.push(t)},t.prototype.go=function(t){var e=!1,n=!1;P.util.isObject(t)&&(e=t.replace,n=t.append),t=this._stringifyPath(t),t&&this.history.go(t,e,n)},t.prototype.replace=function(t){this.go({path:t,replace:!0})},t.prototype.start=function(t,e,n){if(this._started)return void a.warn("already started.");if(this._started=!0,this._startCb=n,!this.app){if(!t||!e)throw new Error("Must start vue-router with a component and a root container.");this._appContainer=e,this._appConstructor="function"==typeof t?t:P.extend(t)}this.history.start()},t.prototype.stop=function(){this.history.stop(),this._started=!1},t.prototype._addRoute=function(t,e,n){if(r(t,e),e.path=t,e.fullPath=(n.reduce(function(t,e){return t+e.path},"")+t).replace("//","/"),n.push({path:t,handler:e}),this._recognizer.add(n,{as:e.name}),e.subRoutes)for(var o in e.subRoutes)this._addRoute(o,e.subRoutes[o],n.slice())},t.prototype._notFound=function(t){r("*",t),this._notFoundHandler=[{handler:t}]},t.prototype._addRedirect=function(t,e){this._addGuard(t,e,this.replace)},t.prototype._addAlias=function(t,e){this._addGuard(t,e,this._match)},t.prototype._addGuard=function(t,e,n){var r=this;this._guardRecognizer.add([{path:t,handler:function(t,o){var i=a.mapParams(e,t.params,o);n.call(r,i)}}])},t.prototype._checkGuard=function(t){var e=this._guardRecognizer.recognize(t);return e?(e[0].handler(e[0],e.queryParams),!0):void 0},t.prototype._match=function(t,e,n){var r=this;if(!this._checkGuard(t)){var o=this._currentRoute,i=this._currentTransition;if(!i||t!==o.path){var a=new p["default"](t,this),s=new v["default"](this,a,o);this._prevTransition=i,this._currentTransition=s,this.app||(this.app=new this._appConstructor({el:this._appContainer,_meta:{$route:a}}));var u=this._beforeEachHooks,c=function(){s.start(function(){r._postTransition(a,e,n)})};u.length?s.runQueue(u,function(t,e,n){s===r._currentTransition&&s.callHook(t,null,n,!0)},c):c(),!this._rendered&&this._startCb&&this._startCb.call(null),this._rendered=!0}}},t.prototype._onTransitionValidated=function(t){var e=this._prevTransition;e&&(e.aborted=!0);var n=this._currentRoute=t.to;this.app.$route!==n&&(this.app.$route=n,this._children.forEach(function(t){t.$route=n})),this._afterEachHooks.length&&this._afterEachHooks.forEach(function(e){return e.call(null,{to:t.to,from:t.from})}),this._currentTransition.done=!0},t.prototype._postTransition=function(t,e,n){var r=e&&e.pos;r&&this._saveScrollPosition?P.nextTick(function(){window.scrollTo(r.x,r.y)}):n&&P.nextTick(function(){var t=document.getElementById(n.slice(1));t&&window.scrollTo(window.scrollX,t.offsetTop)})},t.prototype._stringifyPath=function(t){if(t&&"object"==typeof t){if(t.name){var e=t.params||{};return t.query&&(e.queryParams=t.query),this._recognizer.generate(t.name,e)}return t.path?t.path:""}return t?t+"":""},t}();A.installed=!1,A.install=function(t){if(A.installed)return void a.warn("already installed.");P=t,c["default"](P),m["default"](P),_["default"](P),s["default"].Vue=P;var e=P.config.optionMergeStrategies;e&&(e.route=e.methods),A.installed=!0},"undefined"!=typeof window&&window.Vue&&window.Vue.use(A),e["default"]=A,t.exports=e["default"]},function(t,e){"use strict";e["default"]=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e.__esModule=!0},function(t,e){"use strict";e["default"]=function(t){return t&&t.__esModule?t:{"default":t}},e.__esModule=!0},function(t,e,n){"use strict";function r(t){window.console&&(console.warn("[vue-router] "+t),(!p.Vue||p.Vue.config.debug)&&console.warn(new Error("warning stack trace:").stack))}function o(t,e,n){var r=t.match(/(\?.*)$/);if(r&&(r=r[1],t=t.slice(0,-r.length)),"?"===e.charAt(0))return t+e;var o=t.split("/");n&&o[o.length-1]||o.pop();for(var i=e.replace(/^\//,"").split("/"),a=0;a<i.length;a++){var s=i[a];"."!==s&&(".."===s?o.pop():o.push(s))}return""!==o[0]&&o.unshift(""),o.join("/")}function i(t){return t&&"function"==typeof t.then}function a(t,e){var n=t&&(t.$options||t.options);return n&&n.route&&n.route[e]}function s(t,e){d?d.$options.components._=t.component:d={resolve:p.Vue.prototype._resolveComponent,$options:{components:{_:t.component}}},d.resolve("_",function(n){t.component=n,e(n)})}function u(t,e,n){return void 0===e&&(e={}),t=t.replace(/:([^\/]+)/g,function(n,o){var i=e[o];return i||r('param "'+o+'" not found when generating path for "'+t+'" with params '+JSON.stringify(e)),i||""}),n&&(t+=f(n)),t}var c=n(2)["default"];e.__esModule=!0,e.warn=r,e.resolvePath=o,e.isPromise=i,e.getRouteConfig=a,e.resolveAsyncComponent=s,e.mapParams=u;var h=n(4),l=c(h),f=l["default"].prototype.generateQueryString,p={};e["default"]=p;var d=void 0},function(t,e,n){var r;(function(t){(function(){"use strict";function o(t,e,n){this.path=t,this.matcher=e,this.delegate=n}function i(t){this.routes={},this.children={},this.target=t}function a(t,e,n){return function(r,i){var s=t+r;return i?void i(a(s,e,n)):new o(t+r,e,n)}}function s(t,e,n){for(var r=0,o=0,i=t.length;i>o;o++)r+=t[o].path.length;e=e.substr(r);var a={path:e,handler:n};t.push(a)}function u(t,e,n,r){var o=e.routes;for(var i in o)if(o.hasOwnProperty(i)){var a=t.slice();s(a,i,o[i]),e.children[i]?u(a,e.children[i],n,r):n.call(r,a)}}function c(t){return"[object Array]"===Object.prototype.toString.call(t)}function h(t){this.string=t}function l(t){this.name=t}function f(t){this.name=t}function p(){}function d(t,e,n){"/"===t.charAt(0)&&(t=t.substr(1));var r=t.split("/"),o=[];n.val="";for(var i=0,a=r.length;a>i;i++){var s,u=r[i];(s=u.match(/^:([^\/]+)$/))?(o.push(new l(s[1])),e.push(s[1]),n.val+="3"):(s=u.match(/^\*([^\/]+)$/))?(o.push(new f(s[1])),n.val+="2",e.push(s[1])):""===u?(o.push(new p),n.val+="1"):(o.push(new h(u)),n.val+="4")}return n.val=+n.val,o}function v(t){this.charSpec=t,this.nextStates=[]}function g(t){return t.sort(function(t,e){return e.specificity.val-t.specificity.val})}function m(t,e){for(var n=[],r=0,o=t.length;o>r;r++){var i=t[r];n=n.concat(i.match(e))}return n}function y(t){this.queryParams=t||{}}function _(t,e,n){for(var r=t.handlers,o=t.regex,i=e.match(o),a=1,s=new y(n),u=0,c=r.length;c>u;u++){for(var h=r[u],l=h.names,f={},p=0,d=l.length;d>p;p++)f[l[p]]=i[a++];s.push({handler:h.handler,params:f,isDynamic:!!l.length})}return s}function w(t,e){return e.eachChar(function(e){t=t.put(e)}),t}function b(t){return t=t.replace(/\+/gm,"%20"),decodeURIComponent(t)}o.prototype={to:function(t,e){var n=this.delegate;if(n&&n.willAddRoute&&(t=n.willAddRoute(this.matcher.target,t)),this.matcher.add(this.path,t),e){if(0===e.length)throw new Error("You must have an argument in the function passed to `to`");this.matcher.addChild(this.path,t,e,this.delegate)}return this}},i.prototype={add:function(t,e){this.routes[t]=e},addChild:function(t,e,n,r){var o=new i(e);this.children[t]=o;var s=a(t,o,r);r&&r.contextEntered&&r.contextEntered(e,s),n(s)}};var x=function(t,e){var n=new i;t(a("",n,this.delegate)),u([],n,function(t){e?e(this,t):this.add(t)},this)},C=["/",".","*","+","?","|","(",")","[","]","{","}","\\"],R=new RegExp("(\\"+C.join("|\\")+")","g");h.prototype={eachChar:function(t){for(var e,n=this.string,r=0,o=n.length;o>r;r++)e=n.charAt(r),t({validChars:e})},regex:function(){return this.string.replace(R,"\\$1")},generate:function(){return this.string}},l.prototype={eachChar:function(t){t({invalidChars:"/",repeat:!0})},regex:function(){return"([^/]+)"},generate:function(t){return t[this.name]}},f.prototype={eachChar:function(t){t({invalidChars:"",repeat:!0})},regex:function(){return"(.+)"},generate:function(t){return t[this.name]}},p.prototype={eachChar:function(){},regex:function(){return""},generate:function(){return""}},v.prototype={get:function(t){for(var e=this.nextStates,n=0,r=e.length;r>n;n++){var o=e[n],i=o.charSpec.validChars===t.validChars;if(i=i&&o.charSpec.invalidChars===t.invalidChars)return o}},put:function(t){var e;return(e=this.get(t))?e:(e=new v(t),this.nextStates.push(e),t.repeat&&e.nextStates.push(e),e)},match:function(t){for(var e,n,r,o=this.nextStates,i=[],a=0,s=o.length;s>a;a++)e=o[a],n=e.charSpec,"undefined"!=typeof(r=n.validChars)?-1!==r.indexOf(t)&&i.push(e):"undefined"!=typeof(r=n.invalidChars)&&-1===r.indexOf(t)&&i.push(e);return i}};var $=Object.create||function(t){function e(){}return e.prototype=t,new e};y.prototype=$({splice:Array.prototype.splice,slice:Array.prototype.slice,push:Array.prototype.push,length:0,queryParams:null});var E=function(){this.rootState=new v,this.names={}};E.prototype={add:function(t,e){for(var n,r=this.rootState,o="^",i={},a=[],s=[],u=!0,c=0,h=t.length;h>c;c++){var l=t[c],f=[],v=d(l.path,f,i);s=s.concat(v);for(var g=0,m=v.length;m>g;g++){var y=v[g];y instanceof p||(u=!1,r=r.put({validChars:"/"}),o+="/",r=w(r,y),o+=y.regex())}var _={handler:l.handler,names:f};a.push(_)}u&&(r=r.put({validChars:"/"}),o+="/"),r.handlers=a,r.regex=new RegExp(o+"$"),r.specificity=i,(n=e&&e.as)&&(this.names[n]={segments:s,handlers:a})},handlersFor:function(t){var e=this.names[t],n=[];if(!e)throw new Error("There is no route named "+t);for(var r=0,o=e.handlers.length;o>r;r++)n.push(e.handlers[r]);return n},hasRoute:function(t){return!!this.names[t]},generate:function(t,e){var n=this.names[t],r="";if(!n)throw new Error("There is no route named "+t);for(var o=n.segments,i=0,a=o.length;a>i;i++){var s=o[i];s instanceof p||(r+="/",r+=s.generate(e))}return"/"!==r.charAt(0)&&(r="/"+r),e&&e.queryParams&&(r+=this.generateQueryString(e.queryParams,n.handlers)),r},generateQueryString:function(t,e){var n=[],r=[];for(var o in t)t.hasOwnProperty(o)&&r.push(o);r.sort();for(var i=0,a=r.length;a>i;i++){o=r[i];var s=t[o];if(null!=s){var u=encodeURIComponent(o);if(c(s))for(var h=0,l=s.length;l>h;h++){var f=o+"[]="+encodeURIComponent(s[h]);n.push(f)}else u+="="+encodeURIComponent(s),n.push(u)}}return 0===n.length?"":"?"+n.join("&")},parseQueryString:function(t){for(var e=t.split("&"),n={},r=0;r<e.length;r++){var o,i=e[r].split("="),a=b(i[0]),s=a.length,u=!1;1===i.length?o="true":(s>2&&"[]"===a.slice(s-2)&&(u=!0,a=a.slice(0,s-2),n[a]||(n[a]=[])),o=i[1]?b(i[1]):""),u?n[a].push(o):n[a]=o}return n},recognize:function(t){var e,n,r,o,i=[this.rootState],a={},s=!1;if(o=t.indexOf("?"),-1!==o){var u=t.substr(o+1,t.length);t=t.substr(0,o),a=this.parseQueryString(u)}for(t=decodeURI(t),"/"!==t.charAt(0)&&(t="/"+t),e=t.length,e>1&&"/"===t.charAt(e-1)&&(t=t.substr(0,e-1),s=!0),n=0,r=t.length;r>n&&(i=m(i,t.charAt(n)),i.length);n++);var c=[];for(n=0,r=i.length;r>n;n++)i[n].handlers&&c.push(i[n]);i=g(c);var h=c[0];return h&&h.handlers?(s&&"(.+)$"===h.regex.source.slice(-5)&&(t+="/"),_(h,t,a)):void 0}},E.prototype.map=x,E.VERSION="0.1.9";var P=E;n(6).amd?(r=function(){return P}.call(e,n,e,t),!(void 0!==r&&(t.exports=r))):"undefined"!=typeof t&&t.exports?t.exports=P:"undefined"!=typeof this&&(this.RouteRecognizer=P)}).call(this)}).call(e,n(5)(t))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e){t.exports=function(){throw new Error("define cannot be used indirect")}},function(t,e){"use strict";e.__esModule=!0,e["default"]=function(t){var e=t.util,n={init:function(){var t=this.$root.$route;t&&(t.router._children.push(this),this.$route||e.defineReactive(this,"$route",t))},beforeDestroy:function(){var t=this.$root.$route;t&&t.router._children.$remove(this)}};t.config.optionMergeStrategies&&t.config.optionMergeStrategies.init||!function(){delete n.init;var r=t.prototype._init;t.prototype._init=function(t){var n=t._parent||t.parent||this,o=n.$route;o&&(o.router._children.push(this),this.$route||(this._defineMeta?this._defineMeta("$route",o):e.defineReactive(this,"$route",o))),r.call(this,t)}}(),t.mixin?t.mixin(n):t.options=e.mergeOptions(t.options,n)},t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"],o=n(9)["default"];e.__esModule=!0;var i=/^(component|subRoutes)$/,a=function s(t,e){var n=this;r(this,s);var a=e._recognizer.recognize(t);a&&([].forEach.call(a,function(t){for(var e in t.handler)i.test(e)||(n[e]=t.handler[e])}),this.query=a.queryParams,this.params=[].reduce.call(a,function(t,e){if(e.params)for(var n in e.params)t[n]=e.params[n];return t},{})),this.path=t,this.router=e,this.matched=a||e._notFoundHandler,o(this)};e["default"]=a,t.exports=e["default"]},function(t,e,n){t.exports={"default":n(10),__esModule:!0}},function(t,e,n){n(11),t.exports=n(16).Object.freeze},function(t,e,n){var r=n(12);n(13)("freeze",function(t){return function(e){return t&&r(e)?t(e):e}})},function(t,e){t.exports=function(t){return null!==t&&("object"==typeof t||"function"==typeof t)}},function(t,e,n){t.exports=function(t,e){var r=n(14),o=(n(16).Object||{})[t]||Object[t],i={};i[t]=e(o),r(r.S+r.F*n(17)(function(){o(1)}),"Object",i)}},function(t,e,n){var r=n(15),o=n(16),i="prototype",a=function(t,e){return function(){return t.apply(e,arguments)}},s=function(t,e,n){var u,c,h,l,f=t&s.G,p=t&s.P,d=f?r:t&s.S?r[e]:(r[e]||{})[i],v=f?o:o[e]||(o[e]={});f&&(n=e);for(u in n)c=!(t&s.F)&&d&&u in d,c&&u in v||(h=c?d[u]:n[u],f&&"function"!=typeof d[u]?l=n[u]:t&s.B&&c?l=a(h,r):t&s.W&&d[u]==h?!function(t){l=function(e){return this instanceof t?new t(e):t(e)},l[i]=t[i]}(h):l=p&&"function"==typeof h?a(Function.call,h):h,v[u]=l,p&&((v[i]||(v[i]={}))[u]=h))};s.F=1,s.G=2,s.S=4,s.P=8,s.B=16,s.W=32,t.exports=s},function(t,e){var n="undefined",r=t.exports=typeof window!=n&&window.Math==Math?window:typeof self!=n&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},function(t,e){var n=t.exports={};"number"==typeof __e&&(__e=n)},function(t,e){t.exports=function(t){try{return!!t()}catch(e){return!0}}},function(t,e,n){"use strict";function r(t){return"[object Object]"===Object.prototype.toString.call(t)}var o=n(1)["default"];e.__esModule=!0;var i=n(3),a=n(19),s=function(){function t(e,n,r){o(this,t),this.router=e,this.to=n,this.from=r,this.next=null,this.aborted=!1,this.done=!1,this.deactivateQueue=e._views;var i=n.matched?Array.prototype.slice.call(n.matched):[];this.activateQueue=i.map(function(t){return t.handler})}return t.prototype.abort=function(){if(!this.aborted){this.aborted=!0;var t=!this.from.path&&"/"===this.to.path;t||this.router.replace(this.from.path||"/")}},t.prototype.redirect=function(t){this.aborted||(this.aborted=!0,"string"==typeof t?t=i.mapParams(t,this.to.params,this.to.query):(t.params=this.to.params,t.query=this.to.query),this.router.replace(t))},t.prototype.start=function(t){var e=this,n=this.deactivateQueue,r=this.activateQueue,o=n.slice().reverse(),i=void 0,s=void 0;for(s=0;s<o.length&&a.canReuse(o[s],r[s],e);s++);s>0&&(i=o.slice(0,s),n=o.slice(s).reverse(),r=r.slice(s)),e.runQueue(n,a.canDeactivate,function(){e.runQueue(r,a.canActivate,function(){e.runQueue(n,a.deactivate,function(){if(e.router._onTransitionValidated(e),i&&i.forEach(function(t){a.reuse(t,e)}),n.length){var r=n[n.length-1],o=i?i.length:0;a.activate(r,e,o,t)}else t()})})})},t.prototype.runQueue=function(t,e,n){function r(i){i>=t.length?n():e(t[i],o,function(){r(i+1)})}var o=this;r(0)},t.prototype.callHook=function(t,e,n){var o=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],a=o.expectBoolean,s=void 0===a?!1:a,u=o.expectData,c=void 0===u?!1:u,h=o.cleanup,l=this,f=!1,p=function(t){h&&h(),l.abort(t)},d=function(t){if(h?v():p(),t&&!l.router._suppress)throw i.warn("Uncaught error during transition: "),t instanceof Error?t:new Error(t)},v=function(t){return f?void i.warn("transition.next() should be called only once."):(f=!0,void(n&&!l.aborted&&n(t,d)))},g={to:l.to,from:l.from,abort:p,next:v,redirect:function(){l.redirect.apply(l,arguments)}},m=void 0;try{m=t.call(e,g)}catch(y){return d(y)}var _=i.isPromise(m);s?"boolean"==typeof m?m?v():p():_&&m.then(function(t){t?v():p()},d):_?m.then(v,d):c&&r(m)&&v(m)},t}();e["default"]=s,t.exports=e["default"]},function(t,e,n){"use strict";function r(t,e,n){var r=t.childVM;if(!r||!e)return!1;if(t.Component!==e.component)return!1;var o=l.getRouteConfig(r,"canReuse");return"boolean"==typeof o?o:o?o.call(r,{to:n.to,from:n.from}):!0}function o(t,e,n){var r=t.childVM,o=l.getRouteConfig(r,"canDeactivate");o?e.callHook(o,r,n,{expectBoolean:!0}):n()}function i(t,e,n){l.resolveAsyncComponent(t,function(t){if(!e.aborted){var r=l.getRouteConfig(t,"canActivate");r?e.callHook(r,null,n,{expectBoolean:!0}):n()}})}function a(t,e,n){var r=t.childVM,o=l.getRouteConfig(r,"deactivate");o?e.callHook(o,r,n):n()}function s(t,e,n,r){var o=e.activateQueue[n];if(!o)return t._bound&&t.setComponent(null),void(r&&r());var i=t.Component=o.component,a=l.getRouteConfig(i,"activate"),u=l.getRouteConfig(i,"data"),h=l.getRouteConfig(i,"waitForData");t.depth=n,t.activated=!1,t.unbuild(!0);var f=t.build({_meta:{$loadingRouteData:!(!u||h)}}),p=function(){f.$destroy()},d=function(){var n=e.router;n._rendered||n._transitionOnLoad?t.transition(f):(t.setCurrent?t.setCurrent(f):t.childVM=f,f.$before(t.anchor,null,!1)),r&&r()},v=function(){t.activated=!0,t.childView&&s(t.childView,e,n+1),u&&h?c(f,e,u,d,p):(u&&c(f,e,u),d())};a?e.callHook(a,f,v,{cleanup:p}):v()}function u(t,e){var n=t.childVM,r=l.getRouteConfig(n,"data");r&&c(n,e,r)}function c(t,e,n,r,o){t.$loadingRouteData=!0,e.callHook(n,t,function(e,n){var o=[];h(e).forEach(function(n){var r=e[n];l.isPromise(r)?o.push(r.then(function(e){t.$set(n,e)})):t.$set(n,r)}),o.length?o[0].constructor.all(o).then(function(e){t.$loadingRouteData=!1},n):t.$loadingRouteData=!1,r&&r(e)},{cleanup:o,expectData:!0})}var h=n(20)["default"];e.__esModule=!0,e.canReuse=r,e.canDeactivate=o,e.canActivate=i,e.deactivate=a,e.activate=s,e.reuse=u;var l=n(3)},function(t,e,n){t.exports={"default":n(21),__esModule:!0}},function(t,e,n){n(22),t.exports=n(16).Object.keys},function(t,e,n){var r=n(23);n(13)("keys",function(t){return function(e){return t(r(e))}})},function(t,e,n){var r=n(24);t.exports=function(t){return Object(r(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(3),o=n(19);e["default"]=function(t){var e=t.util,n=t.directive("_component")||t.internalDirectives.component,i=e.extend({},n);e.extend(i,{_isRouterView:!0,bind:function(){var t=this.vm.$route;if(!t)return void r.warn("<router-view> can only be used inside a router-enabled app.");this._isDynamicLiteral=!0,n.bind.call(this),this.keepAlive&&(this.keepAlive=!1,r.warn("<router-view> does not support keep-alive."));var e=this.router=t.router;e._views.unshift(this);var i=e._views[1];i&&(i.childView=this);var a=t.router._currentTransition;if(!i&&a.done||i&&i.activated){var s=i?i.depth+1:0;o.activate(this,a,s)}},unbind:function(){this.router._views.$remove(this),n.unbind.call(this)}}),t.elementDirective("router-view",i)},t.exports=e["default"]},function(t,e,n){"use strict";e.__esModule=!0;var r=n(3),o=/[-.*+?^${}()|[\]\/\\]/g;e["default"]=function(t){function e(t){return t.protocol===location.protocol&&t.hostname===location.hostname&&t.port===location.port}var n=t.util;t.directive("link",{bind:function(){var t=this,o=this.vm;if(!o.$route)return void r.warn("v-link can only be used inside a router-enabled app.");var i=o.$route.router;this.handler=function(n){if(!(n.metaKey||n.ctrlKey||n.shiftKey||n.defaultPrevented||0!==n.button)){var r=t.target;if("A"===t.el.tagName||n.target===t.el)n.preventDefault(),null!=r&&i.go(r);else{for(var o=n.target;o&&"A"!==o.tagName&&o!==t.el;)o=o.parentNode;if(!o||"A"!==o.tagName||!o.href)return;e(o)&&(n.preventDefault(),i.go({path:o.pathname,replace:r&&r.replace,append:r&&r.append}))}}},this.el.addEventListener("click",this.handler),this.unwatch=o.$watch("$route.path",n.bind(this.updateClasses,this))},update:function(t){var e=this.vm.$route.router,r=void 0;this.target=t,n.isObject(t)&&(r=t.append,this.exact=t.exact,this.prevActiveClass=this.activeClass,this.activeClass=t.activeClass),t=this.path=e._stringifyPath(t),this.activeRE=t&&!this.exact?new RegExp("^"+t.replace(/\/$/,"").replace(o,"\\$&")+"(\\/|$)"):null,this.updateClasses(this.vm.$route.path);var i="/"===t.charAt(0),a=t&&("hash"===e.mode||i)?e.history.formatPath(t,r):t;"A"===this.el.tagName&&(a?this.el.href=a:this.el.removeAttribute("href"))},updateClasses:function(t){var e=this.el,r=this.path,o=this.vm.$route.router,i=this.activeClass||o._linkActiveClass;this.prevActiveClass!==i&&n.removeClass(e,this.prevActiveClass),this.exact?t===r?n.addClass(e,i):n.removeClass(e,i):this.activeRE&&this.activeRE.test(t)?n.addClass(e,i):n.removeClass(e,i)},unbind:function(){this.el.removeEventListener("click",this.handler),this.unwatch&&this.unwatch()}})},t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"];e.__esModule=!0;var o=n(3),i=function(){function t(e){var n=e.onChange;r(this,t),this.onChange=n,this.currentPath="/"}return t.prototype.start=function(){this.onChange("/")},t.prototype.stop=function(){},t.prototype.go=function(t,e,n){t=this.currentPath=this.formatPath(t,n),this.onChange(t)},t.prototype.formatPath=function(t,e){return"/"===t.charAt(0)?t:o.resolvePath(this.currentPath,t,e)},t}();e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"];e.__esModule=!0;var o=n(3),i=function(){function t(e){var n=e.hashbang,o=e.onChange;r(this,t),this.hashbang=n,this.onChange=o}return t.prototype.start=function(){var t=this;this.listener=function(){var e=location.hash,n=e.replace(/^#!?/,"");"/"!==n.charAt(0)&&(n="/"+n);var r=t.formatPath(n);if(r!==e)return void location.replace(r);var o=decodeURI(e.replace(/^#!?/,"")+location.search);t.onChange(o)},window.addEventListener("hashchange",this.listener),this.listener()},t.prototype.stop=function(){window.removeEventListener("hashchange",this.listener)},t.prototype.go=function(t,e,n){t=this.formatPath(t,n),e?location.replace(t):location.hash=t},t.prototype.formatPath=function(t,e){var n="/"===t.charAt(0),r="#"+(this.hashbang?"!":"");return n?r+t:r+o.resolvePath(location.hash.replace(/^#!?/,""),t,e)},t}();e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";var r=n(1)["default"];e.__esModule=!0;var o=n(3),i=/#.*$/,a=function(){function t(e){var n=e.root,o=e.onChange;r(this,t),n?("/"!==n.charAt(0)&&(n="/"+n),this.root=n.replace(/\/$/,""),this.rootRE=new RegExp("^\\"+this.root)):this.root=null,this.onChange=o;var i=document.querySelector("base");this.base=i&&i.getAttribute("href")}return t.prototype.start=function(){var t=this;this.listener=function(e){var n=decodeURI(location.pathname+location.search);t.root&&(n=n.replace(t.rootRE,"")),t.onChange(n,e&&e.state,location.hash)},window.addEventListener("popstate",this.listener),this.listener()},t.prototype.stop=function(){window.removeEventListener("popstate",this.listener)},t.prototype.go=function(t,e,n){var r=this.formatPath(t,n);e?history.replaceState({},"",r):(history.replaceState({pos:{x:window.pageXOffset,y:window.pageYOffset}},""),history.pushState({},"",r));var o=t.match(i),a=o&&o[0];t=r.replace(i,"").replace(this.rootRE,""),this.onChange(t,null,a)},t.prototype.formatPath=function(t,e){return"/"===t.charAt(0)?this.root?this.root+"/"+t.replace(/^\//,""):t:o.resolvePath(this.base||location.pathname,t,e)},t}();e["default"]=a,t.exports=e["default"]}])}); |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -26,3 +24,3 @@ var _util = require('../util'); | ||
if (!vm.$route) { | ||
(0, _util.warn)('v-link can only be used inside a ' + 'router-enabled app.'); | ||
_util.warn('v-link can only be used inside a ' + 'router-enabled app.'); | ||
return; | ||
@@ -83,3 +81,3 @@ } | ||
// do not format non-hash relative paths | ||
var href = router.mode === 'hash' || isAbsolute ? router.history.formatPath(path, append) : path; | ||
var href = path && (router.mode === 'hash' || isAbsolute) ? router.history.formatPath(path, append) : path; | ||
if (this.el.tagName === 'A') { | ||
@@ -86,0 +84,0 @@ if (href) { |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -31,3 +29,3 @@ var _util = require('../util'); | ||
if (!route) { | ||
(0, _util.warn)('<router-view> can only be used inside a ' + 'router-enabled app.'); | ||
_util.warn('<router-view> can only be used inside a ' + 'router-enabled app.'); | ||
return; | ||
@@ -45,3 +43,3 @@ } | ||
this.keepAlive = false; | ||
(0, _util.warn)('<router-view> does not support keep-alive.'); | ||
_util.warn('<router-view> does not support keep-alive.'); | ||
} | ||
@@ -74,3 +72,3 @@ | ||
var depth = parentView ? parentView.depth + 1 : 0; | ||
(0, _pipeline.activate)(this, transition, depth); | ||
_pipeline.activate(this, transition, depth); | ||
} | ||
@@ -77,0 +75,0 @@ }, |
'use strict'; | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -23,25 +19,19 @@ var _util = require('../util'); | ||
_createClass(AbstractHistory, [{ | ||
key: 'start', | ||
value: function start() { | ||
this.onChange('/'); | ||
} | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
// noop | ||
} | ||
}, { | ||
key: 'go', | ||
value: function go(path, replace, append) { | ||
path = this.currentPath = this.formatPath(path, append); | ||
this.onChange(path); | ||
} | ||
}, { | ||
key: 'formatPath', | ||
value: function formatPath(path, append) { | ||
return path.charAt(0) === '/' ? path : (0, _util.resolvePath)(this.currentPath, path, append); | ||
} | ||
}]); | ||
AbstractHistory.prototype.start = function start() { | ||
this.onChange('/'); | ||
}; | ||
AbstractHistory.prototype.stop = function stop() { | ||
// noop | ||
}; | ||
AbstractHistory.prototype.go = function go(path, replace, append) { | ||
path = this.currentPath = this.formatPath(path, append); | ||
this.onChange(path); | ||
}; | ||
AbstractHistory.prototype.formatPath = function formatPath(path, append) { | ||
return path.charAt(0) === '/' ? path : _util.resolvePath(this.currentPath, path, append); | ||
}; | ||
return AbstractHistory; | ||
@@ -48,0 +38,0 @@ })(); |
'use strict'; | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -24,48 +20,42 @@ var _util = require('../util'); | ||
_createClass(HashHistory, [{ | ||
key: 'start', | ||
value: function start() { | ||
var self = this; | ||
this.listener = function () { | ||
var path = location.hash; | ||
var raw = path.replace(/^#!?/, ''); | ||
// always | ||
if (raw.charAt(0) !== '/') { | ||
raw = '/' + raw; | ||
} | ||
var formattedPath = self.formatPath(raw); | ||
if (formattedPath !== path) { | ||
location.replace(formattedPath); | ||
return; | ||
} | ||
var pathToMatch = decodeURI(path.replace(/^#!?/, '') + location.search); | ||
self.onChange(pathToMatch); | ||
}; | ||
window.addEventListener('hashchange', this.listener); | ||
this.listener(); | ||
} | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
window.removeEventListener('hashchange', this.listener); | ||
} | ||
}, { | ||
key: 'go', | ||
value: function go(path, replace, append) { | ||
path = this.formatPath(path, append); | ||
if (replace) { | ||
location.replace(path); | ||
} else { | ||
location.hash = path; | ||
HashHistory.prototype.start = function start() { | ||
var self = this; | ||
this.listener = function () { | ||
var path = location.hash; | ||
var raw = path.replace(/^#!?/, ''); | ||
// always | ||
if (raw.charAt(0) !== '/') { | ||
raw = '/' + raw; | ||
} | ||
var formattedPath = self.formatPath(raw); | ||
if (formattedPath !== path) { | ||
location.replace(formattedPath); | ||
return; | ||
} | ||
var pathToMatch = decodeURI(path.replace(/^#!?/, '') + location.search); | ||
self.onChange(pathToMatch); | ||
}; | ||
window.addEventListener('hashchange', this.listener); | ||
this.listener(); | ||
}; | ||
HashHistory.prototype.stop = function stop() { | ||
window.removeEventListener('hashchange', this.listener); | ||
}; | ||
HashHistory.prototype.go = function go(path, replace, append) { | ||
path = this.formatPath(path, append); | ||
if (replace) { | ||
location.replace(path); | ||
} else { | ||
location.hash = path; | ||
} | ||
}, { | ||
key: 'formatPath', | ||
value: function formatPath(path, append) { | ||
var isAbsoloute = path.charAt(0) === '/'; | ||
var prefix = '#' + (this.hashbang ? '!' : ''); | ||
return isAbsoloute ? prefix + path : prefix + (0, _util.resolvePath)(location.hash.replace(/^#!?/, ''), path, append); | ||
} | ||
}]); | ||
}; | ||
HashHistory.prototype.formatPath = function formatPath(path, append) { | ||
var isAbsoloute = path.charAt(0) === '/'; | ||
var prefix = '#' + (this.hashbang ? '!' : ''); | ||
return isAbsoloute ? prefix + path : prefix + _util.resolvePath(location.hash.replace(/^#!?/, ''), path, append); | ||
}; | ||
return HashHistory; | ||
@@ -72,0 +62,0 @@ })(); |
'use strict'; | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -39,57 +35,51 @@ var _util = require('../util'); | ||
_createClass(HTML5History, [{ | ||
key: 'start', | ||
value: function start() { | ||
var _this = this; | ||
HTML5History.prototype.start = function start() { | ||
var _this = this; | ||
this.listener = function (e) { | ||
var url = decodeURI(location.pathname + location.search); | ||
if (_this.root) { | ||
url = url.replace(_this.rootRE, ''); | ||
this.listener = function (e) { | ||
var url = decodeURI(location.pathname + location.search); | ||
if (_this.root) { | ||
url = url.replace(_this.rootRE, ''); | ||
} | ||
_this.onChange(url, e && e.state, location.hash); | ||
}; | ||
window.addEventListener('popstate', this.listener); | ||
this.listener(); | ||
}; | ||
HTML5History.prototype.stop = function stop() { | ||
window.removeEventListener('popstate', this.listener); | ||
}; | ||
HTML5History.prototype.go = function go(path, replace, append) { | ||
var url = this.formatPath(path, append); | ||
if (replace) { | ||
history.replaceState({}, '', url); | ||
} else { | ||
// record scroll position by replacing current state | ||
history.replaceState({ | ||
pos: { | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
} | ||
_this.onChange(url, e && e.state, location.hash); | ||
}; | ||
window.addEventListener('popstate', this.listener); | ||
this.listener(); | ||
}, ''); | ||
// then push new state | ||
history.pushState({}, '', url); | ||
} | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
window.removeEventListener('popstate', this.listener); | ||
} | ||
}, { | ||
key: 'go', | ||
value: function go(path, replace, append) { | ||
var url = this.formatPath(path, append); | ||
if (replace) { | ||
history.replaceState({}, '', url); | ||
} else { | ||
// record scroll position by replacing current state | ||
history.replaceState({ | ||
pos: { | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
} | ||
}, ''); | ||
// then push new state | ||
history.pushState({}, '', url); | ||
} | ||
var hashMatch = path.match(hashRE); | ||
var hash = hashMatch && hashMatch[0]; | ||
path = url | ||
// strip hash so it doesn't mess up params | ||
.replace(hashRE, '') | ||
// remove root before matching | ||
.replace(this.rootRE, ''); | ||
this.onChange(path, null, hash); | ||
} | ||
}, { | ||
key: 'formatPath', | ||
value: function formatPath(path, append) { | ||
return path.charAt(0) === '/' | ||
// absolute path | ||
? this.root ? this.root + '/' + path.replace(/^\//, '') : path : (0, _util.resolvePath)(this.base || location.pathname, path, append); | ||
} | ||
}]); | ||
var hashMatch = path.match(hashRE); | ||
var hash = hashMatch && hashMatch[0]; | ||
path = url | ||
// strip hash so it doesn't mess up params | ||
.replace(hashRE, '') | ||
// remove root before matching | ||
.replace(this.rootRE, ''); | ||
this.onChange(path, null, hash); | ||
}; | ||
HTML5History.prototype.formatPath = function formatPath(path, append) { | ||
return path.charAt(0) === '/' | ||
// absolute path | ||
? this.root ? this.root + '/' + path.replace(/^\//, '') : path : _util.resolvePath(this.base || location.pathname, path, append); | ||
}; | ||
return HTML5History; | ||
@@ -96,0 +86,0 @@ })(); |
731
lib/index.js
'use strict'; | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default']; | ||
@@ -9,5 +7,3 @@ | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -164,447 +160,408 @@ var _util = require('./util'); | ||
_createClass(Router, [{ | ||
key: 'map', | ||
value: function map(_map) { | ||
for (var route in _map) { | ||
this.on(route, _map[route]); | ||
} | ||
Router.prototype.map = function map(_map) { | ||
for (var route in _map) { | ||
this.on(route, _map[route]); | ||
} | ||
}; | ||
/** | ||
* Register a single root-level path | ||
* | ||
* @param {String} rootPath | ||
* @param {Object} handler | ||
* - {String} component | ||
* - {Object} [subRoutes] | ||
* - {Boolean} [forceRefresh] | ||
* - {Function} [before] | ||
* - {Function} [after] | ||
*/ | ||
/** | ||
* Register a single root-level path | ||
* | ||
* @param {String} rootPath | ||
* @param {Object} handler | ||
* - {String} component | ||
* - {Object} [subRoutes] | ||
* - {Boolean} [forceRefresh] | ||
* - {Function} [before] | ||
* - {Function} [after] | ||
*/ | ||
}, { | ||
key: 'on', | ||
value: function on(rootPath, handler) { | ||
if (rootPath === '*') { | ||
this._notFound(handler); | ||
} else { | ||
this._addRoute(rootPath, handler, []); | ||
} | ||
Router.prototype.on = function on(rootPath, handler) { | ||
if (rootPath === '*') { | ||
this._notFound(handler); | ||
} else { | ||
this._addRoute(rootPath, handler, []); | ||
} | ||
}; | ||
/** | ||
* Set redirects. | ||
* | ||
* @param {Object} map | ||
*/ | ||
/** | ||
* Set redirects. | ||
* | ||
* @param {Object} map | ||
*/ | ||
}, { | ||
key: 'redirect', | ||
value: function redirect(map) { | ||
for (var path in map) { | ||
this._addRedirect(path, map[path]); | ||
} | ||
Router.prototype.redirect = function redirect(map) { | ||
for (var path in map) { | ||
this._addRedirect(path, map[path]); | ||
} | ||
}; | ||
/** | ||
* Set aliases. | ||
* | ||
* @param {Object} map | ||
*/ | ||
/** | ||
* Set aliases. | ||
* | ||
* @param {Object} map | ||
*/ | ||
}, { | ||
key: 'alias', | ||
value: function alias(map) { | ||
for (var path in map) { | ||
this._addAlias(path, map[path]); | ||
} | ||
Router.prototype.alias = function alias(map) { | ||
for (var path in map) { | ||
this._addAlias(path, map[path]); | ||
} | ||
}; | ||
/** | ||
* Set global before hook. | ||
* | ||
* @param {Function} fn | ||
*/ | ||
/** | ||
* Set global before hook. | ||
* | ||
* @param {Function} fn | ||
*/ | ||
}, { | ||
key: 'beforeEach', | ||
value: function beforeEach(fn) { | ||
this._beforeEachHooks.push(fn); | ||
} | ||
Router.prototype.beforeEach = function beforeEach(fn) { | ||
this._beforeEachHooks.push(fn); | ||
}; | ||
/** | ||
* Set global after hook. | ||
* | ||
* @param {Function} fn | ||
*/ | ||
/** | ||
* Set global after hook. | ||
* | ||
* @param {Function} fn | ||
*/ | ||
}, { | ||
key: 'afterEach', | ||
value: function afterEach(fn) { | ||
this._afterEachHooks.push(fn); | ||
} | ||
Router.prototype.afterEach = function afterEach(fn) { | ||
this._afterEachHooks.push(fn); | ||
}; | ||
/** | ||
* Navigate to a given path. | ||
* The path can be an object describing a named path in | ||
* the format of { name: '...', params: {}, query: {}} | ||
* The path is assumed to be already decoded, and will | ||
* be resolved against root (if provided) | ||
* | ||
* @param {String|Object} path | ||
* @param {Boolean} [replace] | ||
*/ | ||
/** | ||
* Navigate to a given path. | ||
* The path can be an object describing a named path in | ||
* the format of { name: '...', params: {}, query: {}} | ||
* The path is assumed to be already decoded, and will | ||
* be resolved against root (if provided) | ||
* | ||
* @param {String|Object} path | ||
* @param {Boolean} [replace] | ||
*/ | ||
}, { | ||
key: 'go', | ||
value: function go(path) { | ||
var replace = false; | ||
var append = false; | ||
if (Vue.util.isObject(path)) { | ||
replace = path.replace; | ||
append = path.append; | ||
} | ||
path = this._stringifyPath(path); | ||
Router.prototype.go = function go(path) { | ||
var replace = false; | ||
var append = false; | ||
if (Vue.util.isObject(path)) { | ||
replace = path.replace; | ||
append = path.append; | ||
} | ||
path = this._stringifyPath(path); | ||
if (path) { | ||
this.history.go(path, replace, append); | ||
} | ||
}; | ||
/** | ||
* Short hand for replacing current path | ||
* | ||
* @param {String} path | ||
*/ | ||
/** | ||
* Short hand for replacing current path | ||
* | ||
* @param {String} path | ||
*/ | ||
}, { | ||
key: 'replace', | ||
value: function replace(path) { | ||
this.go({ path: path, replace: true }); | ||
} | ||
Router.prototype.replace = function replace(path) { | ||
this.go({ path: path, replace: true }); | ||
}; | ||
/** | ||
* Start the router. | ||
* | ||
* @param {VueConstructor} App | ||
* @param {String|Element} container | ||
* @param {Function} [cb] | ||
*/ | ||
/** | ||
* Start the router. | ||
* | ||
* @param {VueConstructor} App | ||
* @param {String|Element} container | ||
* @param {Function} [cb] | ||
*/ | ||
}, { | ||
key: 'start', | ||
value: function start(App, container, cb) { | ||
Router.prototype.start = function start(App, container, cb) { | ||
/* istanbul ignore if */ | ||
if (this._started) { | ||
_util.warn('already started.'); | ||
return; | ||
} | ||
this._started = true; | ||
this._startCb = cb; | ||
if (!this.app) { | ||
/* istanbul ignore if */ | ||
if (this._started) { | ||
(0, _util.warn)('already started.'); | ||
return; | ||
if (!App || !container) { | ||
throw new Error('Must start vue-router with a component and a ' + 'root container.'); | ||
} | ||
this._started = true; | ||
this._startCb = cb; | ||
if (!this.app) { | ||
/* istanbul ignore if */ | ||
if (!App || !container) { | ||
throw new Error('Must start vue-router with a component and a ' + 'root container.'); | ||
} | ||
this._appContainer = container; | ||
this._appConstructor = typeof App === 'function' ? App : Vue.extend(App); | ||
} | ||
this.history.start(); | ||
this._appContainer = container; | ||
this._appConstructor = typeof App === 'function' ? App : Vue.extend(App); | ||
} | ||
this.history.start(); | ||
}; | ||
/** | ||
* Stop listening to route changes. | ||
*/ | ||
/** | ||
* Stop listening to route changes. | ||
*/ | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
this.history.stop(); | ||
this._started = false; | ||
} | ||
Router.prototype.stop = function stop() { | ||
this.history.stop(); | ||
this._started = false; | ||
}; | ||
// Internal methods ====================================== | ||
// Internal methods ====================================== | ||
/** | ||
* Add a route containing a list of segments to the internal | ||
* route recognizer. Will be called recursively to add all | ||
* possible sub-routes. | ||
* | ||
* @param {String} path | ||
* @param {Object} handler | ||
* @param {Array} segments | ||
*/ | ||
/** | ||
* Add a route containing a list of segments to the internal | ||
* route recognizer. Will be called recursively to add all | ||
* possible sub-routes. | ||
* | ||
* @param {String} path | ||
* @param {Object} handler | ||
* @param {Array} segments | ||
*/ | ||
}, { | ||
key: '_addRoute', | ||
value: function _addRoute(path, handler, segments) { | ||
guardComponent(path, handler); | ||
handler.path = path; | ||
handler.fullPath = (segments.reduce(function (path, segment) { | ||
return path + segment.path; | ||
}, '') + path).replace('//', '/'); | ||
segments.push({ | ||
path: path, | ||
handler: handler | ||
}); | ||
this._recognizer.add(segments, { | ||
as: handler.name | ||
}); | ||
// add sub routes | ||
if (handler.subRoutes) { | ||
for (var subPath in handler.subRoutes) { | ||
// recursively walk all sub routes | ||
this._addRoute(subPath, handler.subRoutes[subPath], | ||
// pass a copy in recursion to avoid mutating | ||
// across branches | ||
segments.slice()); | ||
} | ||
Router.prototype._addRoute = function _addRoute(path, handler, segments) { | ||
guardComponent(path, handler); | ||
handler.path = path; | ||
handler.fullPath = (segments.reduce(function (path, segment) { | ||
return path + segment.path; | ||
}, '') + path).replace('//', '/'); | ||
segments.push({ | ||
path: path, | ||
handler: handler | ||
}); | ||
this._recognizer.add(segments, { | ||
as: handler.name | ||
}); | ||
// add sub routes | ||
if (handler.subRoutes) { | ||
for (var subPath in handler.subRoutes) { | ||
// recursively walk all sub routes | ||
this._addRoute(subPath, handler.subRoutes[subPath], | ||
// pass a copy in recursion to avoid mutating | ||
// across branches | ||
segments.slice()); | ||
} | ||
} | ||
}; | ||
/** | ||
* Set the notFound route handler. | ||
* | ||
* @param {Object} handler | ||
*/ | ||
/** | ||
* Set the notFound route handler. | ||
* | ||
* @param {Object} handler | ||
*/ | ||
}, { | ||
key: '_notFound', | ||
value: function _notFound(handler) { | ||
guardComponent('*', handler); | ||
this._notFoundHandler = [{ handler: handler }]; | ||
} | ||
Router.prototype._notFound = function _notFound(handler) { | ||
guardComponent('*', handler); | ||
this._notFoundHandler = [{ handler: handler }]; | ||
}; | ||
/** | ||
* Add a redirect record. | ||
* | ||
* @param {String} path | ||
* @param {String} redirectPath | ||
*/ | ||
/** | ||
* Add a redirect record. | ||
* | ||
* @param {String} path | ||
* @param {String} redirectPath | ||
*/ | ||
}, { | ||
key: '_addRedirect', | ||
value: function _addRedirect(path, redirectPath) { | ||
this._addGuard(path, redirectPath, this.replace); | ||
} | ||
Router.prototype._addRedirect = function _addRedirect(path, redirectPath) { | ||
this._addGuard(path, redirectPath, this.replace); | ||
}; | ||
/** | ||
* Add an alias record. | ||
* | ||
* @param {String} path | ||
* @param {String} aliasPath | ||
*/ | ||
/** | ||
* Add an alias record. | ||
* | ||
* @param {String} path | ||
* @param {String} aliasPath | ||
*/ | ||
}, { | ||
key: '_addAlias', | ||
value: function _addAlias(path, aliasPath) { | ||
this._addGuard(path, aliasPath, this._match); | ||
} | ||
Router.prototype._addAlias = function _addAlias(path, aliasPath) { | ||
this._addGuard(path, aliasPath, this._match); | ||
}; | ||
/** | ||
* Add a path guard. | ||
* | ||
* @param {String} path | ||
* @param {String} mappedPath | ||
* @param {Function} handler | ||
*/ | ||
/** | ||
* Add a path guard. | ||
* | ||
* @param {String} path | ||
* @param {String} mappedPath | ||
* @param {Function} handler | ||
*/ | ||
}, { | ||
key: '_addGuard', | ||
value: function _addGuard(path, mappedPath, _handler) { | ||
var _this = this; | ||
Router.prototype._addGuard = function _addGuard(path, mappedPath, _handler) { | ||
var _this = this; | ||
this._guardRecognizer.add([{ | ||
path: path, | ||
handler: function handler(match, query) { | ||
var realPath = (0, _util.mapParams)(mappedPath, match.params, query); | ||
_handler.call(_this, realPath); | ||
} | ||
}]); | ||
} | ||
this._guardRecognizer.add([{ | ||
path: path, | ||
handler: function handler(match, query) { | ||
var realPath = _util.mapParams(mappedPath, match.params, query); | ||
_handler.call(_this, realPath); | ||
} | ||
}]); | ||
}; | ||
/** | ||
* Check if a path matches any redirect records. | ||
* | ||
* @param {String} path | ||
* @return {Boolean} - if true, will skip normal match. | ||
*/ | ||
/** | ||
* Check if a path matches any redirect records. | ||
* | ||
* @param {String} path | ||
* @return {Boolean} - if true, will skip normal match. | ||
*/ | ||
}, { | ||
key: '_checkGuard', | ||
value: function _checkGuard(path) { | ||
var matched = this._guardRecognizer.recognize(path); | ||
if (matched) { | ||
matched[0].handler(matched[0], matched.queryParams); | ||
return true; | ||
} | ||
Router.prototype._checkGuard = function _checkGuard(path) { | ||
var matched = this._guardRecognizer.recognize(path); | ||
if (matched) { | ||
matched[0].handler(matched[0], matched.queryParams); | ||
return true; | ||
} | ||
}; | ||
/** | ||
* Match a URL path and set the route context on vm, | ||
* triggering view updates. | ||
* | ||
* @param {String} path | ||
* @param {Object} [state] | ||
* @param {String} [anchor] | ||
*/ | ||
/** | ||
* Match a URL path and set the route context on vm, | ||
* triggering view updates. | ||
* | ||
* @param {String} path | ||
* @param {Object} [state] | ||
* @param {String} [anchor] | ||
*/ | ||
}, { | ||
key: '_match', | ||
value: function _match(path, state, anchor) { | ||
var _this2 = this; | ||
Router.prototype._match = function _match(path, state, anchor) { | ||
var _this2 = this; | ||
if (this._checkGuard(path)) { | ||
return; | ||
} | ||
if (this._checkGuard(path)) { | ||
return; | ||
} | ||
var prevRoute = this._currentRoute; | ||
var prevTransition = this._currentTransition; | ||
var prevRoute = this._currentRoute; | ||
var prevTransition = this._currentTransition; | ||
// do nothing if going to the same route. | ||
// the route only changes when a transition successfully | ||
// reaches activation; we don't need to do anything | ||
// if an ongoing transition is aborted during validation | ||
// phase. | ||
if (prevTransition && path === prevRoute.path) { | ||
return; | ||
} | ||
// do nothing if going to the same route. | ||
// the route only changes when a transition successfully | ||
// reaches activation; we don't need to do anything | ||
// if an ongoing transition is aborted during validation | ||
// phase. | ||
if (prevTransition && path === prevRoute.path) { | ||
return; | ||
} | ||
// construct new route and transition context | ||
var route = new _route2['default'](path, this); | ||
var transition = new _transition2['default'](this, route, prevRoute); | ||
this._prevTransition = prevTransition; | ||
this._currentTransition = transition; | ||
// construct new route and transition context | ||
var route = new _route2['default'](path, this); | ||
var transition = new _transition2['default'](this, route, prevRoute); | ||
this._prevTransition = prevTransition; | ||
this._currentTransition = transition; | ||
if (!this.app) { | ||
// initial render | ||
this.app = new this._appConstructor({ | ||
el: this._appContainer, | ||
_meta: { | ||
$route: route | ||
} | ||
}); | ||
} | ||
if (!this.app) { | ||
// initial render | ||
this.app = new this._appConstructor({ | ||
el: this._appContainer, | ||
_meta: { | ||
$route: route | ||
} | ||
}); | ||
} | ||
// check global before hook | ||
var beforeHooks = this._beforeEachHooks; | ||
var startTransition = function startTransition() { | ||
transition.start(function () { | ||
_this2._postTransition(route, state, anchor); | ||
}); | ||
}; | ||
// check global before hook | ||
var beforeHooks = this._beforeEachHooks; | ||
var startTransition = function startTransition() { | ||
transition.start(function () { | ||
_this2._postTransition(route, state, anchor); | ||
}); | ||
}; | ||
if (beforeHooks.length) { | ||
transition.runQueue(beforeHooks, function (hook, _, next) { | ||
if (transition === _this2._currentTransition) { | ||
transition.callHook(hook, null, next, true); | ||
} | ||
}, startTransition); | ||
} else { | ||
startTransition(); | ||
} | ||
if (beforeHooks.length) { | ||
transition.runQueue(beforeHooks, function (hook, _, next) { | ||
if (transition === _this2._currentTransition) { | ||
transition.callHook(hook, null, next, true); | ||
} | ||
}, startTransition); | ||
} else { | ||
startTransition(); | ||
} | ||
if (!this._rendered && this._startCb) { | ||
this._startCb.call(null); | ||
} | ||
// HACK: | ||
// set rendered to true after the transition start, so | ||
// that components that are acitvated synchronously know | ||
// whether it is the initial render. | ||
this._rendered = true; | ||
if (!this._rendered && this._startCb) { | ||
this._startCb.call(null); | ||
} | ||
/** | ||
* Set current to the new transition. | ||
* This is called by the transition object when the | ||
* validation of a route has succeeded. | ||
* | ||
* @param {Transition} transition | ||
*/ | ||
// HACK: | ||
// set rendered to true after the transition start, so | ||
// that components that are acitvated synchronously know | ||
// whether it is the initial render. | ||
this._rendered = true; | ||
}; | ||
}, { | ||
key: '_onTransitionValidated', | ||
value: function _onTransitionValidated(transition) { | ||
// now that this one is validated, we can abort | ||
// the previous transition. | ||
var prevTransition = this._prevTransition; | ||
if (prevTransition) { | ||
prevTransition.aborted = true; | ||
} | ||
// set current route | ||
var route = this._currentRoute = transition.to; | ||
// update route context for all children | ||
if (this.app.$route !== route) { | ||
this.app.$route = route; | ||
this._children.forEach(function (child) { | ||
child.$route = route; | ||
/** | ||
* Set current to the new transition. | ||
* This is called by the transition object when the | ||
* validation of a route has succeeded. | ||
* | ||
* @param {Transition} transition | ||
*/ | ||
Router.prototype._onTransitionValidated = function _onTransitionValidated(transition) { | ||
// now that this one is validated, we can abort | ||
// the previous transition. | ||
var prevTransition = this._prevTransition; | ||
if (prevTransition) { | ||
prevTransition.aborted = true; | ||
} | ||
// set current route | ||
var route = this._currentRoute = transition.to; | ||
// update route context for all children | ||
if (this.app.$route !== route) { | ||
this.app.$route = route; | ||
this._children.forEach(function (child) { | ||
child.$route = route; | ||
}); | ||
} | ||
// call global after hook | ||
if (this._afterEachHooks.length) { | ||
this._afterEachHooks.forEach(function (hook) { | ||
return hook.call(null, { | ||
to: transition.to, | ||
from: transition.from | ||
}); | ||
} | ||
// call global after hook | ||
if (this._afterEachHooks.length) { | ||
this._afterEachHooks.forEach(function (hook) { | ||
return hook.call(null, { | ||
to: transition.to, | ||
from: transition.from | ||
}); | ||
}); | ||
} | ||
this._currentTransition.done = true; | ||
}); | ||
} | ||
this._currentTransition.done = true; | ||
}; | ||
/** | ||
* Handle stuff after the transition. | ||
* | ||
* @param {Route} route | ||
* @param {Object} [state] | ||
* @param {String} [anchor] | ||
*/ | ||
/** | ||
* Handle stuff after the transition. | ||
* | ||
* @param {Route} route | ||
* @param {Object} [state] | ||
* @param {String} [anchor] | ||
*/ | ||
}, { | ||
key: '_postTransition', | ||
value: function _postTransition(route, state, anchor) { | ||
// handle scroll positions | ||
// saved scroll positions take priority | ||
// then we check if the path has an anchor | ||
var pos = state && state.pos; | ||
if (pos && this._saveScrollPosition) { | ||
Vue.nextTick(function () { | ||
window.scrollTo(pos.x, pos.y); | ||
}); | ||
} else if (anchor) { | ||
Vue.nextTick(function () { | ||
var el = document.getElementById(anchor.slice(1)); | ||
if (el) { | ||
window.scrollTo(window.scrollX, el.offsetTop); | ||
} | ||
}); | ||
} | ||
Router.prototype._postTransition = function _postTransition(route, state, anchor) { | ||
// handle scroll positions | ||
// saved scroll positions take priority | ||
// then we check if the path has an anchor | ||
var pos = state && state.pos; | ||
if (pos && this._saveScrollPosition) { | ||
Vue.nextTick(function () { | ||
window.scrollTo(pos.x, pos.y); | ||
}); | ||
} else if (anchor) { | ||
Vue.nextTick(function () { | ||
var el = document.getElementById(anchor.slice(1)); | ||
if (el) { | ||
window.scrollTo(window.scrollX, el.offsetTop); | ||
} | ||
}); | ||
} | ||
}; | ||
/** | ||
* Normalize named route object / string paths into | ||
* a string. | ||
* | ||
* @param {Object|String|Number} path | ||
* @return {String} | ||
*/ | ||
/** | ||
* Normalize named route object / string paths into | ||
* a string. | ||
* | ||
* @param {Object|String|Number} path | ||
* @return {String} | ||
*/ | ||
}, { | ||
key: '_stringifyPath', | ||
value: function _stringifyPath(path) { | ||
if (typeof path === 'object') { | ||
if (path.name) { | ||
var params = path.params || {}; | ||
if (path.query) { | ||
params.queryParams = path.query; | ||
} | ||
return this._recognizer.generate(path.name, params); | ||
} else if (path.path) { | ||
return path.path; | ||
} else { | ||
return ''; | ||
Router.prototype._stringifyPath = function _stringifyPath(path) { | ||
if (path && typeof path === 'object') { | ||
if (path.name) { | ||
var params = path.params || {}; | ||
if (path.query) { | ||
params.queryParams = path.query; | ||
} | ||
return this._recognizer.generate(path.name, params); | ||
} else if (path.path) { | ||
return path.path; | ||
} else { | ||
return path + ''; | ||
return ''; | ||
} | ||
} else { | ||
return path ? path + '' : ''; | ||
} | ||
}]); | ||
}; | ||
@@ -622,3 +579,3 @@ return Router; | ||
handler.component = null; | ||
(0, _util.warn)('invalid component for route "' + path + '".'); | ||
_util.warn('invalid component for route "' + path + '".'); | ||
} | ||
@@ -639,9 +596,9 @@ } | ||
if (Router.installed) { | ||
(0, _util.warn)('already installed.'); | ||
_util.warn('already installed.'); | ||
return; | ||
} | ||
Vue = externalVue; | ||
(0, _mixin2['default'])(Vue); | ||
(0, _directivesView2['default'])(Vue); | ||
(0, _directivesLink2['default'])(Vue); | ||
_mixin2['default'](Vue); | ||
_directivesView2['default'](Vue); | ||
_directivesLink2['default'](Vue); | ||
_util2['default'].Vue = Vue; | ||
@@ -648,0 +605,0 @@ // 1.0 only: enable route mixins |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -11,3 +9,3 @@ exports['default'] = function (Vue) { | ||
var mixin = { | ||
created: function created() { | ||
init: function init() { | ||
var route = this.$root.$route; | ||
@@ -17,8 +15,3 @@ if (route) { | ||
if (!this.$route) { | ||
if (this._defineMeta) { | ||
// 0.12 compat | ||
this._defineMeta('$route', route); | ||
} else { | ||
_.defineReactive(this, '$route', route); | ||
} | ||
_.defineReactive(this, '$route', route); | ||
} | ||
@@ -35,2 +28,25 @@ } | ||
// pre 1.0.0-rc compat | ||
if (!Vue.config.optionMergeStrategies || !Vue.config.optionMergeStrategies.init) { | ||
(function () { | ||
delete mixin.init; | ||
var init = Vue.prototype._init; | ||
Vue.prototype._init = function (options) { | ||
var root = options._parent || options.parent || this; | ||
var route = root.$route; | ||
if (route) { | ||
route.router._children.push(this); | ||
if (!this.$route) { | ||
if (this._defineMeta) { | ||
this._defineMeta('$route', route); | ||
} else { | ||
_.defineReactive(this, '$route', route); | ||
} | ||
} | ||
} | ||
init.call(this, options); | ||
}; | ||
})(); | ||
} | ||
if (Vue.mixin) { | ||
@@ -37,0 +53,0 @@ Vue.mixin(mixin); |
@@ -5,5 +5,3 @@ 'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
exports.canReuse = canReuse; | ||
@@ -36,3 +34,3 @@ exports.canDeactivate = canDeactivate; | ||
} | ||
var canReuseFn = (0, _util.getRouteConfig)(component, 'canReuse'); | ||
var canReuseFn = _util.getRouteConfig(component, 'canReuse'); | ||
return typeof canReuseFn === 'boolean' ? canReuseFn : canReuseFn ? canReuseFn.call(component, { | ||
@@ -54,3 +52,3 @@ to: transition.to, | ||
var fromComponent = view.childVM; | ||
var hook = (0, _util.getRouteConfig)(fromComponent, 'canDeactivate'); | ||
var hook = _util.getRouteConfig(fromComponent, 'canDeactivate'); | ||
if (!hook) { | ||
@@ -74,3 +72,3 @@ next(); | ||
function canActivate(handler, transition, next) { | ||
(0, _util.resolveAsyncComponent)(handler, function (Component) { | ||
_util.resolveAsyncComponent(handler, function (Component) { | ||
// have to check due to async-ness | ||
@@ -81,3 +79,3 @@ if (transition.aborted) { | ||
// determine if this component can be activated | ||
var hook = (0, _util.getRouteConfig)(Component, 'canActivate'); | ||
var hook = _util.getRouteConfig(Component, 'canActivate'); | ||
if (!hook) { | ||
@@ -103,3 +101,3 @@ next(); | ||
var component = view.childVM; | ||
var hook = (0, _util.getRouteConfig)(component, 'deactivate'); | ||
var hook = _util.getRouteConfig(component, 'deactivate'); | ||
if (!hook) { | ||
@@ -133,5 +131,5 @@ next(); | ||
var Component = view.Component = handler.component; | ||
var activateHook = (0, _util.getRouteConfig)(Component, 'activate'); | ||
var dataHook = (0, _util.getRouteConfig)(Component, 'data'); | ||
var waitForData = (0, _util.getRouteConfig)(Component, 'waitForData'); | ||
var activateHook = _util.getRouteConfig(Component, 'activate'); | ||
var dataHook = _util.getRouteConfig(Component, 'data'); | ||
var waitForData = _util.getRouteConfig(Component, 'waitForData'); | ||
@@ -183,3 +181,3 @@ view.depth = depth; | ||
if (view.childView) { | ||
exports.activate(view.childView, transition, depth + 1); | ||
activate(view.childView, transition, depth + 1); | ||
} | ||
@@ -216,3 +214,3 @@ if (dataHook && waitForData) { | ||
var component = view.childVM; | ||
var dataHook = (0, _util.getRouteConfig)(component, 'data'); | ||
var dataHook = _util.getRouteConfig(component, 'data'); | ||
if (dataHook) { | ||
@@ -239,3 +237,3 @@ loadData(component, transition, dataHook); | ||
var val = data[key]; | ||
if ((0, _util.isPromise)(val)) { | ||
if (_util.isPromise(val)) { | ||
promises.push(val.then(function (resolvedVal) { | ||
@@ -242,0 +240,0 @@ component.$set(key, resolvedVal); |
@@ -7,5 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
var internalKeysRE = /^(component|subRoutes)$/; | ||
@@ -12,0 +10,0 @@ |
'use strict'; | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -57,239 +53,228 @@ var _util = require('./util'); | ||
_createClass(RouteTransition, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
if (!this.aborted) { | ||
this.aborted = true; | ||
// if the root path throws an error during validation | ||
// on initial load, it gets caught in an infinite loop. | ||
var abortingOnLoad = !this.from.path && this.to.path === '/'; | ||
if (!abortingOnLoad) { | ||
this.router.replace(this.from.path || '/'); | ||
} | ||
RouteTransition.prototype.abort = function abort() { | ||
if (!this.aborted) { | ||
this.aborted = true; | ||
// if the root path throws an error during validation | ||
// on initial load, it gets caught in an infinite loop. | ||
var abortingOnLoad = !this.from.path && this.to.path === '/'; | ||
if (!abortingOnLoad) { | ||
this.router.replace(this.from.path || '/'); | ||
} | ||
} | ||
}; | ||
/** | ||
* Abort current transition and redirect to a new location. | ||
* | ||
* @param {String} path | ||
*/ | ||
/** | ||
* Abort current transition and redirect to a new location. | ||
* | ||
* @param {String} path | ||
*/ | ||
}, { | ||
key: 'redirect', | ||
value: function redirect(path) { | ||
if (!this.aborted) { | ||
this.aborted = true; | ||
if (typeof path === 'string') { | ||
path = (0, _util.mapParams)(path, this.to.params, this.to.query); | ||
} else { | ||
path.params = this.to.params; | ||
path.query = this.to.query; | ||
} | ||
this.router.replace(path); | ||
RouteTransition.prototype.redirect = function redirect(path) { | ||
if (!this.aborted) { | ||
this.aborted = true; | ||
if (typeof path === 'string') { | ||
path = _util.mapParams(path, this.to.params, this.to.query); | ||
} else { | ||
path.params = this.to.params; | ||
path.query = this.to.query; | ||
} | ||
this.router.replace(path); | ||
} | ||
}; | ||
/** | ||
* A router view transition's pipeline can be described as | ||
* follows, assuming we are transitioning from an existing | ||
* <router-view> chain [Component A, Component B] to a new | ||
* chain [Component A, Component C]: | ||
* | ||
* A A | ||
* | => | | ||
* B C | ||
* | ||
* 1. Reusablity phase: | ||
* -> canReuse(A, A) | ||
* -> canReuse(B, C) | ||
* -> determine new queues: | ||
* - deactivation: [B] | ||
* - activation: [C] | ||
* | ||
* 2. Validation phase: | ||
* -> canDeactivate(B) | ||
* -> canActivate(C) | ||
* | ||
* 3. Activation phase: | ||
* -> deactivate(B) | ||
* -> activate(C) | ||
* | ||
* Each of these steps can be asynchronous, and any | ||
* step can potentially abort the transition. | ||
* | ||
* @param {Function} cb | ||
*/ | ||
/** | ||
* A router view transition's pipeline can be described as | ||
* follows, assuming we are transitioning from an existing | ||
* <router-view> chain [Component A, Component B] to a new | ||
* chain [Component A, Component C]: | ||
* | ||
* A A | ||
* | => | | ||
* B C | ||
* | ||
* 1. Reusablity phase: | ||
* -> canReuse(A, A) | ||
* -> canReuse(B, C) | ||
* -> determine new queues: | ||
* - deactivation: [B] | ||
* - activation: [C] | ||
* | ||
* 2. Validation phase: | ||
* -> canDeactivate(B) | ||
* -> canActivate(C) | ||
* | ||
* 3. Activation phase: | ||
* -> deactivate(B) | ||
* -> activate(C) | ||
* | ||
* Each of these steps can be asynchronous, and any | ||
* step can potentially abort the transition. | ||
* | ||
* @param {Function} cb | ||
*/ | ||
}, { | ||
key: 'start', | ||
value: function start(cb) { | ||
var transition = this; | ||
var daq = this.deactivateQueue; | ||
var aq = this.activateQueue; | ||
var rdaq = daq.slice().reverse(); | ||
var reuseQueue = undefined; | ||
RouteTransition.prototype.start = function start(cb) { | ||
var transition = this; | ||
var daq = this.deactivateQueue; | ||
var aq = this.activateQueue; | ||
var rdaq = daq.slice().reverse(); | ||
var reuseQueue = undefined; | ||
// 1. Reusability phase | ||
var i = undefined; | ||
for (i = 0; i < rdaq.length; i++) { | ||
if (!(0, _pipeline.canReuse)(rdaq[i], aq[i], transition)) { | ||
break; | ||
} | ||
// 1. Reusability phase | ||
var i = undefined; | ||
for (i = 0; i < rdaq.length; i++) { | ||
if (!_pipeline.canReuse(rdaq[i], aq[i], transition)) { | ||
break; | ||
} | ||
if (i > 0) { | ||
reuseQueue = rdaq.slice(0, i); | ||
daq = rdaq.slice(i).reverse(); | ||
aq = aq.slice(i); | ||
} | ||
} | ||
if (i > 0) { | ||
reuseQueue = rdaq.slice(0, i); | ||
daq = rdaq.slice(i).reverse(); | ||
aq = aq.slice(i); | ||
} | ||
// 2. Validation phase | ||
transition.runQueue(daq, _pipeline.canDeactivate, function () { | ||
transition.runQueue(aq, _pipeline.canActivate, function () { | ||
transition.runQueue(daq, _pipeline.deactivate, function () { | ||
// 3. Activation phase | ||
// 2. Validation phase | ||
transition.runQueue(daq, _pipeline.canDeactivate, function () { | ||
transition.runQueue(aq, _pipeline.canActivate, function () { | ||
transition.runQueue(daq, _pipeline.deactivate, function () { | ||
// 3. Activation phase | ||
// Update router current route | ||
transition.router._onTransitionValidated(transition); | ||
// Update router current route | ||
transition.router._onTransitionValidated(transition); | ||
// trigger reuse for all reused views | ||
reuseQueue && reuseQueue.forEach(function (view) { | ||
(0, _pipeline.reuse)(view, transition); | ||
}); | ||
// trigger reuse for all reused views | ||
reuseQueue && reuseQueue.forEach(function (view) { | ||
_pipeline.reuse(view, transition); | ||
}); | ||
// the root of the chain that needs to be replaced | ||
// is the top-most non-reusable view. | ||
if (daq.length) { | ||
var view = daq[daq.length - 1]; | ||
var depth = reuseQueue ? reuseQueue.length : 0; | ||
(0, _pipeline.activate)(view, transition, depth, cb); | ||
} else { | ||
cb(); | ||
} | ||
}); | ||
// the root of the chain that needs to be replaced | ||
// is the top-most non-reusable view. | ||
if (daq.length) { | ||
var view = daq[daq.length - 1]; | ||
var depth = reuseQueue ? reuseQueue.length : 0; | ||
_pipeline.activate(view, transition, depth, cb); | ||
} else { | ||
cb(); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Asynchronously and sequentially apply a function to a | ||
* queue. | ||
* | ||
* @param {Array} queue | ||
* @param {Function} fn | ||
* @param {Function} cb | ||
*/ | ||
/** | ||
* Asynchronously and sequentially apply a function to a | ||
* queue. | ||
* | ||
* @param {Array} queue | ||
* @param {Function} fn | ||
* @param {Function} cb | ||
*/ | ||
}, { | ||
key: 'runQueue', | ||
value: function runQueue(queue, fn, cb) { | ||
var transition = this; | ||
step(0); | ||
function step(index) { | ||
if (index >= queue.length) { | ||
cb(); | ||
} else { | ||
fn(queue[index], transition, function () { | ||
step(index + 1); | ||
}); | ||
} | ||
RouteTransition.prototype.runQueue = function runQueue(queue, fn, cb) { | ||
var transition = this; | ||
step(0); | ||
function step(index) { | ||
if (index >= queue.length) { | ||
cb(); | ||
} else { | ||
fn(queue[index], transition, function () { | ||
step(index + 1); | ||
}); | ||
} | ||
} | ||
}; | ||
/** | ||
* Call a user provided route transition hook and handle | ||
* the response (e.g. if the user returns a promise). | ||
* | ||
* @param {Function} hook | ||
* @param {*} [context] | ||
* @param {Function} [cb] | ||
* @param {Object} [options] | ||
* - {Boolean} expectBoolean | ||
* - {Boolean} expectData | ||
* - {Function} cleanup | ||
*/ | ||
/** | ||
* Call a user provided route transition hook and handle | ||
* the response (e.g. if the user returns a promise). | ||
* | ||
* @param {Function} hook | ||
* @param {*} [context] | ||
* @param {Function} [cb] | ||
* @param {Object} [options] | ||
* - {Boolean} expectBoolean | ||
* - {Boolean} expectData | ||
* - {Function} cleanup | ||
*/ | ||
}, { | ||
key: 'callHook', | ||
value: function callHook(hook, context, cb) { | ||
var _ref = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
RouteTransition.prototype.callHook = function callHook(hook, context, cb) { | ||
var _ref = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var _ref$expectBoolean = _ref.expectBoolean; | ||
var expectBoolean = _ref$expectBoolean === undefined ? false : _ref$expectBoolean; | ||
var _ref$expectData = _ref.expectData; | ||
var expectData = _ref$expectData === undefined ? false : _ref$expectData; | ||
var cleanup = _ref.cleanup; | ||
var _ref$expectBoolean = _ref.expectBoolean; | ||
var expectBoolean = _ref$expectBoolean === undefined ? false : _ref$expectBoolean; | ||
var _ref$expectData = _ref.expectData; | ||
var expectData = _ref$expectData === undefined ? false : _ref$expectData; | ||
var cleanup = _ref.cleanup; | ||
var transition = this; | ||
var nextCalled = false; | ||
var transition = this; | ||
var nextCalled = false; | ||
// abort the transition | ||
var abort = function abort(back) { | ||
cleanup && cleanup(); | ||
transition.abort(back); | ||
}; | ||
// abort the transition | ||
var abort = function abort(back) { | ||
cleanup && cleanup(); | ||
transition.abort(back); | ||
}; | ||
// handle errors | ||
var onError = function onError(err) { | ||
// cleanup indicates an after-activation hook, | ||
// so instead of aborting we just let the transition | ||
// finish. | ||
cleanup ? next() : abort(); | ||
if (err && !transition.router._suppress) { | ||
(0, _util.warn)('Uncaught error during transition: '); | ||
throw err instanceof Error ? err : new Error(err); | ||
} | ||
}; | ||
// handle errors | ||
var onError = function onError(err) { | ||
// cleanup indicates an after-activation hook, | ||
// so instead of aborting we just let the transition | ||
// finish. | ||
cleanup ? next() : abort(); | ||
if (err && !transition.router._suppress) { | ||
_util.warn('Uncaught error during transition: '); | ||
throw err instanceof Error ? err : new Error(err); | ||
} | ||
}; | ||
// advance the transition to the next step | ||
var next = function next(data) { | ||
if (nextCalled) { | ||
(0, _util.warn)('transition.next() should be called only once.'); | ||
return; | ||
} | ||
nextCalled = true; | ||
if (!cb || transition.aborted) { | ||
return; | ||
} | ||
cb(data, onError); | ||
}; | ||
// advance the transition to the next step | ||
var next = function next(data) { | ||
if (nextCalled) { | ||
_util.warn('transition.next() should be called only once.'); | ||
return; | ||
} | ||
nextCalled = true; | ||
if (!cb || transition.aborted) { | ||
return; | ||
} | ||
cb(data, onError); | ||
}; | ||
// expose a clone of the transition object, so that each | ||
// hook gets a clean copy and prevent the user from | ||
// messing with the internals. | ||
var exposed = { | ||
to: transition.to, | ||
from: transition.from, | ||
abort: abort, | ||
next: next, | ||
redirect: function redirect() { | ||
transition.redirect.apply(transition, arguments); | ||
} | ||
}; | ||
// actually call the hook | ||
var res = undefined; | ||
try { | ||
res = hook.call(context, exposed); | ||
} catch (err) { | ||
return onError(err); | ||
// expose a clone of the transition object, so that each | ||
// hook gets a clean copy and prevent the user from | ||
// messing with the internals. | ||
var exposed = { | ||
to: transition.to, | ||
from: transition.from, | ||
abort: abort, | ||
next: next, | ||
redirect: function redirect() { | ||
transition.redirect.apply(transition, arguments); | ||
} | ||
}; | ||
// handle boolean/promise return values | ||
var resIsPromise = (0, _util.isPromise)(res); | ||
if (expectBoolean) { | ||
if (typeof res === 'boolean') { | ||
res ? next() : abort(); | ||
} else if (resIsPromise) { | ||
res.then(function (ok) { | ||
ok ? next() : abort(); | ||
}, onError); | ||
} | ||
// actually call the hook | ||
var res = undefined; | ||
try { | ||
res = hook.call(context, exposed); | ||
} catch (err) { | ||
return onError(err); | ||
} | ||
// handle boolean/promise return values | ||
var resIsPromise = _util.isPromise(res); | ||
if (expectBoolean) { | ||
if (typeof res === 'boolean') { | ||
res ? next() : abort(); | ||
} else if (resIsPromise) { | ||
res.then(next, onError); | ||
} else if (expectData && isPlainOjbect(res)) { | ||
next(res); | ||
res.then(function (ok) { | ||
ok ? next() : abort(); | ||
}, onError); | ||
} | ||
} else if (resIsPromise) { | ||
res.then(next, onError); | ||
} else if (expectData && isPlainOjbect(res)) { | ||
next(res); | ||
} | ||
}]); | ||
}; | ||
@@ -296,0 +281,0 @@ return RouteTransition; |
@@ -5,5 +5,3 @@ 'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
exports.warn = warn; | ||
@@ -10,0 +8,0 @@ exports.resolvePath = resolvePath; |
{ | ||
"name": "vue-router", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "A router for Vue.js", | ||
@@ -10,3 +10,3 @@ "main": "lib/index.js", | ||
"unit": "./node_modules/karma/bin/karma start build/karma.config.js", | ||
"build": "babel ./src --optional runtime --out-dir lib && webpack --config build/webpack.build.dev.config.js && webpack --config build/webpack.build.min.config.js", | ||
"build": "babel ./src --loose --optional runtime --out-dir lib && webpack --config build/webpack.build.dev.config.js && webpack --config build/webpack.build.min.config.js", | ||
"serve": "webpack-dev-server --hot --config example/advanced/webpack.config.js --content-base example/advanced --history-api-fallback --host 0.0.0.0", | ||
@@ -13,0 +13,0 @@ "serve-test": "webpack-dev-server --quiet --config test/unit/webpack.config.js --content-base test/unit --history-api-fallback --host 0.0.0.0 --port 8081", |
@@ -80,3 +80,3 @@ import { warn } from '../util' | ||
// do not format non-hash relative paths | ||
let href = router.mode === 'hash' || isAbsolute | ||
let href = path && (router.mode === 'hash' || isAbsolute) | ||
? router.history.formatPath(path, append) | ||
@@ -83,0 +83,0 @@ : path |
@@ -203,3 +203,5 @@ import util, { warn, mapParams } from './util' | ||
path = this._stringifyPath(path) | ||
this.history.go(path, replace, append) | ||
if (path) { | ||
this.history.go(path, replace, append) | ||
} | ||
} | ||
@@ -509,3 +511,3 @@ | ||
_stringifyPath (path) { | ||
if (typeof path === 'object') { | ||
if (path && typeof path === 'object') { | ||
if (path.name) { | ||
@@ -523,3 +525,3 @@ var params = path.params || {} | ||
} else { | ||
return path + '' | ||
return path ? path + '' : '' | ||
} | ||
@@ -526,0 +528,0 @@ } |
@@ -5,13 +5,8 @@ export default function (Vue) { | ||
const mixin = { | ||
created: function () { | ||
var route = this.$root.$route | ||
init: function () { | ||
const route = this.$root.$route | ||
if (route) { | ||
route.router._children.push(this) | ||
if (!this.$route) { | ||
if (this._defineMeta) { | ||
// 0.12 compat | ||
this._defineMeta('$route', route) | ||
} else { | ||
_.defineReactive(this, '$route', route) | ||
} | ||
_.defineReactive(this, '$route', route) | ||
} | ||
@@ -21,3 +16,3 @@ } | ||
beforeDestroy: function () { | ||
var route = this.$root.$route | ||
const route = this.$root.$route | ||
if (route) { | ||
@@ -29,2 +24,24 @@ route.router._children.$remove(this) | ||
// pre 1.0.0-rc compat | ||
if (!Vue.config.optionMergeStrategies || | ||
!Vue.config.optionMergeStrategies.init) { | ||
delete mixin.init | ||
const init = Vue.prototype._init | ||
Vue.prototype._init = function (options) { | ||
const root = options._parent || options.parent || this | ||
const route = root.$route | ||
if (route) { | ||
route.router._children.push(this) | ||
if (!this.$route) { | ||
if (this._defineMeta) { | ||
this._defineMeta('$route', route) | ||
} else { | ||
_.defineReactive(this, '$route', route) | ||
} | ||
} | ||
} | ||
init.call(this, options) | ||
} | ||
} | ||
if (Vue.mixin) { | ||
@@ -31,0 +48,0 @@ Vue.mixin(mixin) |
@@ -165,3 +165,3 @@ import { getRouteConfig, resolveAsyncComponent, isPromise } from './util' | ||
if (view.childView) { | ||
exports.activate(view.childView, transition, depth + 1) | ||
activate(view.childView, transition, depth + 1) | ||
} | ||
@@ -168,0 +168,0 @@ if (dataHook && waitForData) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
325769
5923