vue-router
Advanced tools
Comparing version 2.0.0-beta.1 to 2.0.0-beta.2
@@ -188,3 +188,5 @@ (function (global, factory) { | ||
function assert (condition, message) { | ||
/* */ | ||
function assert (condition , message ) { | ||
if (!condition) { | ||
@@ -195,3 +197,3 @@ throw new Error(("[vue-router] " + message)) | ||
function warn (condition, message) { | ||
function warn (condition , message ) { | ||
if (!condition) { | ||
@@ -409,3 +411,3 @@ typeof console !== 'undefined' && console.warn(("[vue-router] " + message)) | ||
this._router = this.$options.router | ||
this._router.app = this | ||
this._router.init(this) | ||
Vue.util.defineReactive(this, '_route', this._router.history.current) | ||
@@ -1040,3 +1042,3 @@ } | ||
} else { | ||
warn(("invalid redirect option: " + (JSON.stringify(redirect)))) | ||
warn(false, ("invalid redirect option: " + (JSON.stringify(redirect)))) | ||
return createRouteContext(null, location) | ||
@@ -1111,3 +1113,3 @@ } | ||
} catch (e) { | ||
assert(("missing param for " + routeMsg + ": " + (e.message))) | ||
assert(false, ("missing param for " + routeMsg + ": " + (e.message))) | ||
return '' | ||
@@ -1209,3 +1211,3 @@ } | ||
// global before hooks | ||
nomralizeGuards(this.router.options.beforeEach), | ||
this.router.beforeHooks, | ||
// activate guards | ||
@@ -1233,3 +1235,3 @@ activated.map(function (m) { return m.beforeEnter; }) | ||
this.cb && this.cb(route) | ||
nomralizeGuards(this.router.options.afterEach).forEach(function (hook) { | ||
this.router.afterHooks.forEach(function (hook) { | ||
hook && hook(route) | ||
@@ -1281,12 +1283,2 @@ }) | ||
function nomralizeGuards (guards ) { | ||
if (!guards) { | ||
return [] | ||
} | ||
if (typeof guards === 'function') { | ||
return [guards] | ||
} | ||
return guards | ||
} | ||
function extractLeaveGuards (matched ) { | ||
@@ -1309,2 +1301,41 @@ return Array.prototype.concat.apply([], matched.map(function (m) { | ||
/* */ | ||
function saveScrollPosition (key ) { | ||
if (!key) return | ||
window.sessionStorage.setItem(key, JSON.stringify({ | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
})) | ||
} | ||
function getScrollPosition (key ) { | ||
if (!key) return | ||
return JSON.parse(window.sessionStorage.getItem(key)) | ||
} | ||
function getElementPosition (el ) { | ||
var docRect = document.documentElement.getBoundingClientRect() | ||
var elRect = el.getBoundingClientRect() | ||
return { | ||
x: elRect.left - docRect.left, | ||
y: elRect.top - docRect.top | ||
} | ||
} | ||
function isValidPosition (obj ) { | ||
return isNumber(obj.x) || isNumber(obj.y) | ||
} | ||
function normalizePosotion (obj ) { | ||
return { | ||
x: isNumber(obj.x) ? obj.x : window.pageXOffset, | ||
y: isNumber(obj.y) ? obj.y : window.pageYOffset | ||
} | ||
} | ||
function isNumber (v ) { | ||
return typeof v === 'number' | ||
} | ||
var genKey = function () { return String(Date.now()); } | ||
@@ -1338,3 +1369,5 @@ var _key = genKey() | ||
if (expectScroll) { | ||
window.addEventListener('scroll', saveScrollPosition) | ||
window.addEventListener('scroll', function () { | ||
saveScrollPosition(_key) | ||
}) | ||
} | ||
@@ -1385,26 +1418,21 @@ } | ||
} | ||
assert(typeof behavior === 'function', "scrollBehavior must be a function") | ||
var position = getScrollPosition() | ||
var shouldScroll = behavior(to, from, isPop ? position : null) | ||
if (!shouldScroll) { | ||
return | ||
} | ||
// wait until re-render finishes before scrolling | ||
router.app.$nextTick(function () { | ||
var position = getScrollPosition(_key) | ||
var shouldScroll = behavior(to, from, isPop ? position : null) | ||
if (!shouldScroll) { | ||
return | ||
} | ||
var isObject = typeof shouldScroll === 'object' | ||
if (isObject && shouldScroll.x != null && shouldScroll.y != null) { | ||
position = shouldScroll | ||
} else if (isObject && shouldScroll.anchor) { | ||
var el = document.querySelector(to.hash) | ||
if (isObject && shouldScroll.selector) { | ||
var el = document.querySelector(shouldScroll.selector) | ||
if (el) { | ||
var docTop = document.documentElement.getBoundingClientRect().top | ||
var elTop = el.getBoundingClientRect().top | ||
position = { | ||
x: window.scrollX, | ||
y: elTop - docTop | ||
} | ||
position = getElementPosition(el) | ||
} else if (isValidPosition(shouldScroll)) { | ||
position = normalizePosotion(shouldScroll) | ||
} | ||
} else if (isObject && isValidPosition(shouldScroll)) { | ||
position = normalizePosotion(shouldScroll) | ||
} | ||
@@ -1440,3 +1468,3 @@ | ||
} | ||
saveScrollPosition() | ||
saveScrollPosition(_key) | ||
} catch (e) { | ||
@@ -1451,15 +1479,2 @@ window.location[replace ? 'assign' : 'replace'](url) | ||
function saveScrollPosition () { | ||
if (!_key) return | ||
window.sessionStorage.setItem(_key, JSON.stringify({ | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
})) | ||
} | ||
function getScrollPosition () { | ||
if (!_key) return | ||
return JSON.parse(window.sessionStorage.getItem(_key)) | ||
} | ||
var HashHistory = (function (History) { | ||
@@ -1611,18 +1626,13 @@ function HashHistory (router , base , fallback ) { | ||
var VueRouter = function VueRouter (options) { | ||
var this$1 = this; | ||
if ( options === void 0 ) options = {}; | ||
assert( | ||
install.installed, | ||
"not installed. Make sure to call `Vue.use(VueRouter)` " + | ||
"before mounting root instance." | ||
) | ||
this.app = null | ||
this.options = options | ||
this.beforeHooks = [] | ||
this.afterHooks = [] | ||
this.match = createMatcher(options.routes || []) | ||
var mode = options.mode || 'hash' | ||
var fallback = mode === 'history' && !supportsHistory | ||
if (fallback) { | ||
this.fallback = mode === 'history' && !supportsHistory | ||
if (this.fallback) { | ||
mode = 'hash' | ||
@@ -1633,3 +1643,18 @@ } | ||
} | ||
this.mode = mode | ||
}; | ||
VueRouter.prototype.init = function init (app /* Vue component instance */) { | ||
var this$1 = this; | ||
assert( | ||
install.installed, | ||
"not installed. Make sure to call `Vue.use(VueRouter)` " + | ||
"before creating root instance." | ||
) | ||
var ref = this; | ||
var mode = ref.mode; | ||
var options = ref.options; | ||
var fallback = ref.fallback; | ||
switch (mode) { | ||
@@ -1649,4 +1674,3 @@ case 'history': | ||
this.mode = mode | ||
this.app = app | ||
this.history.listen(function (route) { | ||
@@ -1657,2 +1681,10 @@ this$1.app._route = route | ||
VueRouter.prototype.beforeEach = function beforeEach (fn ) { | ||
this.beforeHooks.push(fn) | ||
}; | ||
VueRouter.prototype.afterEach = function afterEach (fn ) { | ||
this.afterHooks.push(fn) | ||
}; | ||
VueRouter.prototype.push = function push (location ) { | ||
@@ -1664,9 +1696,9 @@ this.history.push(location) | ||
this.history.replace(location) | ||
}; | ||
}; | ||
VueRouter.prototype.go = function go (n ) { | ||
this.history.go(n) | ||
}; | ||
VueRouter.prototype.go = function go (n ) { | ||
this.history.go(n) | ||
}; | ||
VueRouter.prototype.back = function back () { | ||
VueRouter.prototype.back = function back () { | ||
this.go(-1) | ||
@@ -1673,0 +1705,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if(void 0===e&&(e="/"),"/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i<o.length;i++){var a=o[i];"."!==a&&(".."===a?r.pop():r.push(a))}return""!==r[0]&&r.unshift(""),r.join("/")}function e(t){var e="",n="",r=t.indexOf("#");r>=0&&(e=t.slice(r),t=t.slice(0,r));var o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}function n(t){return t.replace(/\/\//g,"/")}function r(t,e){return!!e&&(t.path&&e.path?t.path===e.path&&t.hash===e.hash&&o(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&o(t.query,e.query)&&o(t.params,e.params)))}function o(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function i(t,e){return 0===t.path.indexOf(e.path)&&(!e.hash||t.hash===e.hash)&&a(t.query,e.query)}function a(t,e){for(var n in e)if(!(n in t))return!1;return!0}function c(t,e){if(!t)throw new Error("[vue-router] "+e)}function u(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function s(t,e){if(void 0===e&&(e={}),t){var n;try{n=p(t)}catch(t){u(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function p(t){var e=Object.create(null);return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=F(n.shift()),o=n.length>0?F(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function h(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return M(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(M(e)):r.push(M(e)+"="+M(t)))}),r.join("&")}return M(e)+"="+M(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function f(n,r,o){var i="string"==typeof n?{path:n}:n;if(i.name||i._normalized)return i;var a=e(i.path||""),c=a.path?t(a.path,r&&r.path,o):r&&r.path||"/",u=s(a.query,i.query),p=i.hash||a.hash;return p&&"#"!==p.charAt(0)&&(p="#"+p),{_normalized:!0,path:c,query:u,hash:p}}function l(t){if(t)for(var e,n=0;n<t.length;n++){if(e=t[n],"a"===e.tag)return e;if(e.children&&(e=l(e.children)))return e}}function d(t){d.installed||(d.installed=!0,Object.defineProperty(t.prototype,"$router",{get:function(){return this.$root._router}}),Object.defineProperty(t.prototype,"$route",{get:function(){return this.$root._route}}),t.mixin({beforeCreate:function(){this.$options.router&&(this._router=this.$options.router,this._router.app=this,t.util.defineReactive(this,"_route",this._router.history.current))}}),t.component("router-view",z),t.component("router-link",J))}function y(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function v(t,e){return e={exports:{}},t(e,e.exports),e.exports}function m(t){var e=Object.create(null),n=Object.create(null);return t.forEach(function(t){g(e,n,t)}),{pathMap:e,nameMap:n}}function g(t,e,n,r,o){var i=n.path,a=n.name;c(null!=i,'"path" is required in a route configuration.');var u={path:w(i,r),components:n.components||{default:n.component},instances:{},name:a,parent:r,matchAs:o,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{}};n.children&&n.children.forEach(function(n){g(t,e,n,u)}),n.alias&&(Array.isArray(n.alias)?n.alias.forEach(function(n){g(t,e,{path:n},r,u.path)}):g(t,e,{path:n.alias},r,u.path)),t[u.path]=u,a&&(e[a]=u)}function w(t,e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:n(e.path+"/"+t)}function b(t){function e(t,e,r){var o=f(t,e),i=o.name;if(i){var c=s[i];if(c)return o.path=k(c.path,o.params,'named route "'+i+'"'),n(c,o,r)}else if(o.path){o.params={};for(var u in a)if(x(u,o.params,o.path))return n(a[u],o,r)}return n(null,o)}function n(t,e,n){if(t&&t.redirect)return r(t,n||e);if(t&&t.matchAs)return o(t,e,t.matchAs);var i={name:e.name,path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:j(e),matched:t?O(t):[]};return n&&(i.redirectedFrom=j(n)),Object.freeze(i)}function r(t,r){var o=r.query,i=r.hash,a=r.params,p=t.redirect,h=p&&"object"==typeof p&&p.name;if(h){var f=s[h];return c(f,'redirect failed: named route "'+h+'" not found.'),e({_normalized:!0,name:h,query:o,hash:i,params:a},void 0,r)}if("string"==typeof p){var l=E(p,t),d=k(l,a,'redirect route with path "'+l+'"');return e({_normalized:!0,path:d,query:o,hash:i},void 0,r)}return u("invalid redirect option: "+JSON.stringify(p)),n(null,r)}function o(t,r,o){var i=k(o,r.params,'aliased route with path "'+o+'"'),a=e({_normalized:!0,path:i});if(a){var c=a.matched,u=c[c.length-1];return r.params=a.params,n(u,r)}return n(null,r)}var i=m(t),a=i.pathMap,s=i.nameMap;return e}function x(t,e,n){var r,o,i=Y[t];i?(r=i.keys,o=i.regexp):(r=[],o=W(t,r),Y[t]={keys:r,regexp:o});var a=n.match(o);if(!a)return!1;if(!e)return!0;for(var c=1,u=a.length;c<u;++c){var s=r[c-1],p="string"==typeof a[c]?decodeURIComponent(a[c]):a[c];s&&(e[s.name]=p)}return!0}function k(t,e,n){try{var r=G[t]||(G[t]=W.compile(t));return r(e||{},{pretty:!0})}catch(t){return c("missing param for "+n+": "+t.message),""}}function O(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function E(e,n){return t(e,n.parent?n.parent.path:"/",!0)}function j(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+h(n)+r}function A(t,e,n){var r=function(o){o>=t.length?n():e(t[o],function(){r(o+1)})};r(0)}function S(t){if(!t)if(K){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function _(t,e){var n,r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{activated:e.slice(n),deactivated:t.slice(n)}}function $(t){return t?"function"==typeof t?[t]:t:[]}function R(t){return Array.prototype.concat.apply([],t.map(function(t){return Object.keys(t.components).map(function(e){var n=t.components[e],r=t.instances[e]&&t.instances[e].child,o="function"==typeof n?n.options.beforeRouteLeave:n&&n.beforeRouteLeave;if(o)return function(){return o.apply(r,arguments)}})}).reverse())}function T(t){var e=window.location.pathname;return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),e+window.location.search+window.location.hash}function q(t,e){var n=window.history;try{e?n.replaceState({key:et},"",t):(et=tt(),n.pushState({key:et},"",t)),L()}catch(n){window.location[e?"assign":"replace"](t)}}function C(t){q(t,!0)}function L(){et&&window.sessionStorage.setItem(et,JSON.stringify({x:window.pageXOffset,y:window.pageYOffset}))}function P(){if(et)return JSON.parse(window.sessionStorage.getItem(et))}function I(){var t=V();return"/"===t.charAt(0)||(U("/"+t),!1)}function V(){var t=window.location.href,e=t.indexOf("#");return e===-1?"":t.slice(e+1)}function B(t){window.location.hash=t}function U(t){var e=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,e>=0?e:0)+"#"+t)}var z={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,c=o._routerViewCache||(o._routerViewCache={}),u=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&u++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=u;var p=a.matched[u];if(!p)return t();var h=s?c[n.name]:c[n.name]=p.components[n.name],f=t(h,i,r);return s||(p.instances[n.name]=f),f}},M=encodeURIComponent,F=decodeURIComponent,J={name:"router-link",props:{to:{type:[String,Object],required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,o=this.$router,a=this.$route,c=f(this.to,a,this.append),u=o.match(c),s=u.redirectedFrom||u.fullPath,p=o.history.base,h=p?n(p+s):s,d={},y=this.activeClass||o.options.linkActiveClass||"router-link-active";d[y]=this.exact?r(a,u):i(a,u);var v={class:d,on:{click:function(t){t.preventDefault(),e.replace?o.replace(c):o.push(c)}}};if("a"===this.tag)v.attrs={href:h};else{var m=l(this.$slots.default);if(m){var g=m.data||(m.data={}),w=g.attrs||(g.attrs={});w.href=h}}return t(this.tag,v,this.$slots.default)}},N=v(function(t){t.exports=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)}}),D=y(N),H=Object.freeze({default:D}),X=v(function(t){function e(t){for(var e,n=[],r=0,o=0,i="";null!=(e=m.exec(t));){var a=e[0],u=e[1],s=e.index;if(i+=t.slice(o,s),o=s+a.length,u)i+=u[1];else{var p=t[o],h=e[2],f=e[3],l=e[4],d=e[5],y=e[6],v=e[7];i&&(n.push(i),i="");var g=null!=h&&null!=p&&p!==h,w="+"===y||"*"===y,b="?"===y||"*"===y,x=e[2]||"/",k=l||d||(v?".*":"[^"+x+"]+?");n.push({name:f||r++,prefix:h||"",delimiter:x,optional:b,repeat:w,partial:g,asterisk:!!v,pattern:c(k)})}}return o<t.length&&(i+=t.substr(o)),i&&n.push(i),n}function n(t){return i(e(t))}function r(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function o(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function i(t){for(var e=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(e[n]=new RegExp("^(?:"+t[n].pattern+")$"));return function(n,i){for(var a="",c=n||{},u=i||{},s=u.pretty?r:encodeURIComponent,p=0;p<t.length;p++){var h=t[p];if("string"!=typeof h){var f,l=c[h.name];if(null==l){if(h.optional){h.partial&&(a+=h.prefix);continue}throw new TypeError('Expected "'+h.name+'" to be defined')}if(v(l)){if(!h.repeat)throw new TypeError('Expected "'+h.name+'" to not repeat, but received `'+JSON.stringify(l)+"`");if(0===l.length){if(h.optional)continue;throw new TypeError('Expected "'+h.name+'" to not be empty')}for(var d=0;d<l.length;d++){if(f=s(l[d]),!e[p].test(f))throw new TypeError('Expected all "'+h.name+'" to match "'+h.pattern+'", but received `'+JSON.stringify(f)+"`");a+=(0===d?h.prefix:h.delimiter)+f}}else{if(f=h.asterisk?o(l):s(l),!e[p].test(f))throw new TypeError('Expected "'+h.name+'" to match "'+h.pattern+'", but received "'+f+'"');a+=h.prefix+f}}else a+=h}return a}}function a(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function c(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function u(t,e){return t.keys=e,t}function s(t){return t.sensitive?"":"i"}function p(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return u(t,e)}function h(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(d(t[o],e,n).source);var i=new RegExp("(?:"+r.join("|")+")",s(n));return u(i,e)}function f(t,n,r){for(var o=e(t),i=l(o,r),a=0;a<o.length;a++)"string"!=typeof o[a]&&n.push(o[a]);return u(i,n)}function l(t,e){e=e||{};for(var n=e.strict,r=e.end!==!1,o="",i=t[t.length-1],c="string"==typeof i&&/\/$/.test(i),u=0;u<t.length;u++){var p=t[u];if("string"==typeof p)o+=a(p);else{var h=a(p.prefix),f="(?:"+p.pattern+")";p.repeat&&(f+="(?:"+h+f+")*"),f=p.optional?p.partial?h+"("+f+")?":"(?:"+h+"("+f+"))?":h+"("+f+")",o+=f}}return n||(o=(c?o.slice(0,-2):o)+"(?:\\/(?=$))?"),o+=r?"$":n&&c?"":"(?=\\/|$)",new RegExp("^"+o,s(e))}function d(t,e,n){return e=e||[],v(e)?n||(n={}):(n=e,e=[]),t instanceof RegExp?p(t,e):v(t)?h(t,e,n):f(t,e,n)}var v=y(H);t.exports=d,t.exports.parse=e,t.exports.compile=n,t.exports.tokensToFunction=i,t.exports.tokensToRegExp=l;var m=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g")}),W=y(X),Y=Object.create(null),G=Object.create(null),K="undefined"!=typeof window,Q=K&&function(){var t=window.navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history)}(),Z=function(t,e){this.router=t,this.base=S(e),this.current=t.match("/"),this.pending=null,this.transitionTo(this.getLocation())};Z.prototype.listen=function(t){this.cb=t},Z.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r)})},Z.prototype.confirmTransition=function(t,e){var n=this;if(!r(t,this.current)){var o=_(this.current.matched,t.matched),i=o.deactivated,a=o.activated,c=[].concat(R(i),$(this.router.options.beforeEach),a.map(function(t){return t.beforeEnter})).filter(function(t){return t});this.pending=t;var u=function(t){return n.push(t)};A(c,function(e,n){e(t,u,n)},function(){r(t,n.pending)&&(n.pending=null,e(t))})}},Z.prototype.updateRoute=function(t){this.current=t,this.cb&&this.cb(t),$(this.router.options.afterEach).forEach(function(e){e&&e(t)})},Z.prototype.getLocation=function(){return"/"};var tt=function(){return String(Date.now())},et=tt(),nt=function(t){function e(e,r){var o=this;t.call(this,e,r);var i=n(this.base+this.current.fullPath);this.getLocation()!==i&&C(i);var a=e.options.scrollBehavior;window.addEventListener("popstate",function(t){et=t.state&&t.state.key;var e=o.current;o.transitionTo(o.getLocation(),function(t){a&&o.handleScroll(t,e,!0)})}),a&&window.addEventListener("scroll",L)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(e){var r=this,o=this.current;t.prototype.transitionTo.call(this,e,function(t){q(n(r.base+t.fullPath)),r.handleScroll(t,o,!1)})},e.prototype.replace=function(e){var r=this,o=this.current;t.prototype.transitionTo.call(this,e,function(t){C(n(r.base+t.fullPath)),r.handleScroll(t,o,!1)})},e.prototype.getLocation=function(){return T(this.base)},e.prototype.handleScroll=function(t,e,n){var r=this.router;if(r.app){var o=r.options.scrollBehavior;if(o){c("function"==typeof o,"scrollBehavior must be a function");var i=P(),a=o(t,e,n?i:null);a&&r.app.$nextTick(function(){var e="object"==typeof a;if(e&&null!=a.x&&null!=a.y)i=a;else if(e&&a.anchor){var n=document.querySelector(t.hash);if(n){var r=document.documentElement.getBoundingClientRect().top,o=n.getBoundingClientRect().top;i={x:window.scrollX,y:o-r}}}i&&window.scrollTo(i.x,i.y)})}}},e}(Z),rt=function(t){function e(e,n,r){var o=this;t.call(this,e,n),r&&this.checkFallback()||(I(),V()!==this.current.fullPath&&U(this.current.fullPath),window.addEventListener("hashchange",function(){o.onHashChange()}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkFallback=function(){var t=T(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.onHashChange=function(){I()&&this.transitionTo(this.getLocation(),function(t){U(t.fullPath)})},e.prototype.push=function(e){t.prototype.transitionTo.call(this,e,function(t){B(t.fullPath)})},e.prototype.replace=function(e){t.prototype.transitionTo.call(this,e,function(t){U(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e.prototype.getLocation=function(){return V()},e}(Z),ot=function(t){function e(e){t.call(this,e),this.stack=[this.current],this.index=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++})},e.prototype.replace=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!this.stack,!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e.prototype.setInitialRoute=function(t){this.current=t,this.stack=[this.current],this.index=0},e}(Z),it=function(t){var e=this;void 0===t&&(t={}),c(d.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before mounting root instance."),this.app=null,this.options=t,this.match=b(t.routes||[]);var n=t.mode||"hash",r="history"===n&&!Q;switch(r&&(n="hash"),K||(n="abstract"),n){case"history":this.history=new nt(this,t.base);break;case"hash":this.history=new rt(this,t.base,r);break;case"abstract":this.history=new ot(this);break;default:c(!1,"invalid mode: "+n)}this.mode=n,this.history.listen(function(t){e.app._route=t})};return it.prototype.push=function(t){this.history.push(t)},it.prototype.replace=function(t){this.history.replace(t)},it.prototype.go=function(t){this.history.go(t)},it.prototype.back=function(){this.go(-1)},it.prototype.forward=function(){this.go(1)},it.prototype.setInitialLocation=function(t){this.history instanceof ot&&this.history.setInitialRoute(this.match(t))},it.install=d,K&&window.Vue&&window.Vue.use(it),it}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if(void 0===e&&(e="/"),"/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i<o.length;i++){var a=o[i];"."!==a&&(".."===a?r.pop():r.push(a))}return""!==r[0]&&r.unshift(""),r.join("/")}function e(t){var e="",n="",r=t.indexOf("#");r>=0&&(e=t.slice(r),t=t.slice(0,r));var o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}function n(t){return t.replace(/\/\//g,"/")}function r(t,e){return!!e&&(t.path&&e.path?t.path===e.path&&t.hash===e.hash&&o(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&o(t.query,e.query)&&o(t.params,e.params)))}function o(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function i(t,e){return 0===t.path.indexOf(e.path)&&(!e.hash||t.hash===e.hash)&&a(t.query,e.query)}function a(t,e){for(var n in e)if(!(n in t))return!1;return!0}function c(t,e){if(!t)throw new Error("[vue-router] "+e)}function u(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function s(t,e){if(void 0===e&&(e={}),t){var n;try{n=p(t)}catch(t){u(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function p(t){var e=Object.create(null);return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=N(n.shift()),o=n.length>0?N(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function h(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return J(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(J(e)):r.push(J(e)+"="+J(t)))}),r.join("&")}return J(e)+"="+J(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function f(n,r,o){var i="string"==typeof n?{path:n}:n;if(i.name||i._normalized)return i;var a=e(i.path||""),c=a.path?t(a.path,r&&r.path,o):r&&r.path||"/",u=s(a.query,i.query),p=i.hash||a.hash;return p&&"#"!==p.charAt(0)&&(p="#"+p),{_normalized:!0,path:c,query:u,hash:p}}function l(t){if(t)for(var e,n=0;n<t.length;n++){if(e=t[n],"a"===e.tag)return e;if(e.children&&(e=l(e.children)))return e}}function d(t){d.installed||(d.installed=!0,Object.defineProperty(t.prototype,"$router",{get:function(){return this.$root._router}}),Object.defineProperty(t.prototype,"$route",{get:function(){return this.$root._route}}),t.mixin({beforeCreate:function(){this.$options.router&&(this._router=this.$options.router,this._router.init(this),t.util.defineReactive(this,"_route",this._router.history.current))}}),t.component("router-view",F),t.component("router-link",D))}function y(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function v(t,e){return e={exports:{}},t(e,e.exports),e.exports}function m(t){var e=Object.create(null),n=Object.create(null);return t.forEach(function(t){g(e,n,t)}),{pathMap:e,nameMap:n}}function g(t,e,n,r,o){var i=n.path,a=n.name;c(null!=i,'"path" is required in a route configuration.');var u={path:w(i,r),components:n.components||{default:n.component},instances:{},name:a,parent:r,matchAs:o,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{}};n.children&&n.children.forEach(function(n){g(t,e,n,u)}),n.alias&&(Array.isArray(n.alias)?n.alias.forEach(function(n){g(t,e,{path:n},r,u.path)}):g(t,e,{path:n.alias},r,u.path)),t[u.path]=u,a&&(e[a]=u)}function w(t,e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:n(e.path+"/"+t)}function b(t){function e(t,e,r){var o=f(t,e),i=o.name;if(i){var c=s[i];if(c)return o.path=k(c.path,o.params,'named route "'+i+'"'),n(c,o,r)}else if(o.path){o.params={};for(var u in a)if(x(u,o.params,o.path))return n(a[u],o,r)}return n(null,o)}function n(t,e,n){if(t&&t.redirect)return r(t,n||e);if(t&&t.matchAs)return o(t,e,t.matchAs);var i={name:e.name,path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:j(e),matched:t?O(t):[]};return n&&(i.redirectedFrom=j(n)),Object.freeze(i)}function r(t,r){var o=r.query,i=r.hash,a=r.params,p=t.redirect,h=p&&"object"==typeof p&&p.name;if(h){var f=s[h];return c(f,'redirect failed: named route "'+h+'" not found.'),e({_normalized:!0,name:h,query:o,hash:i,params:a},void 0,r)}if("string"==typeof p){var l=E(p,t),d=k(l,a,'redirect route with path "'+l+'"');return e({_normalized:!0,path:d,query:o,hash:i},void 0,r)}return u(!1,"invalid redirect option: "+JSON.stringify(p)),n(null,r)}function o(t,r,o){var i=k(o,r.params,'aliased route with path "'+o+'"'),a=e({_normalized:!0,path:i});if(a){var c=a.matched,u=c[c.length-1];return r.params=a.params,n(u,r)}return n(null,r)}var i=m(t),a=i.pathMap,s=i.nameMap;return e}function x(t,e,n){var r,o,i=Q[t];i?(r=i.keys,o=i.regexp):(r=[],o=K(t,r),Q[t]={keys:r,regexp:o});var a=n.match(o);if(!a)return!1;if(!e)return!0;for(var c=1,u=a.length;c<u;++c){var s=r[c-1],p="string"==typeof a[c]?decodeURIComponent(a[c]):a[c];s&&(e[s.name]=p)}return!0}function k(t,e,n){try{var r=Z[t]||(Z[t]=K.compile(t));return r(e||{},{pretty:!0})}catch(t){return c(!1,"missing param for "+n+": "+t.message),""}}function O(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function E(e,n){return t(e,n.parent?n.parent.path:"/",!0)}function j(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+h(n)+r}function A(t,e,n){var r=function(o){o>=t.length?n():e(t[o],function(){r(o+1)})};r(0)}function S(t){if(!t)if(tt){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function _(t,e){var n,r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{activated:e.slice(n),deactivated:t.slice(n)}}function $(t){return Array.prototype.concat.apply([],t.map(function(t){return Object.keys(t.components).map(function(e){var n=t.components[e],r=t.instances[e]&&t.instances[e].child,o="function"==typeof n?n.options.beforeRouteLeave:n&&n.beforeRouteLeave;if(o)return function(){return o.apply(r,arguments)}})}).reverse())}function R(t){t&&window.sessionStorage.setItem(t,JSON.stringify({x:window.pageXOffset,y:window.pageYOffset}))}function T(t){if(t)return JSON.parse(window.sessionStorage.getItem(t))}function q(t){var e=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top}}function C(t){return P(t.x)||P(t.y)}function L(t){return{x:P(t.x)?t.x:window.pageXOffset,y:P(t.y)?t.y:window.pageYOffset}}function P(t){return"number"==typeof t}function I(t){var e=window.location.pathname;return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),e+window.location.search+window.location.hash}function V(t,e){var n=window.history;try{e?n.replaceState({key:ot},"",t):(ot=rt(),n.pushState({key:ot},"",t)),R(ot)}catch(n){window.location[e?"assign":"replace"](t)}}function B(t){V(t,!0)}function H(){var t=U();return"/"===t.charAt(0)||(M("/"+t),!1)}function U(){var t=window.location.href,e=t.indexOf("#");return e===-1?"":t.slice(e+1)}function z(t){window.location.hash=t}function M(t){var e=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,e>=0?e:0)+"#"+t)}var F={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,c=o._routerViewCache||(o._routerViewCache={}),u=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&u++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=u;var p=a.matched[u];if(!p)return t();var h=s?c[n.name]:c[n.name]=p.components[n.name],f=t(h,i,r);return s||(p.instances[n.name]=f),f}},J=encodeURIComponent,N=decodeURIComponent,D={name:"router-link",props:{to:{type:[String,Object],required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,o=this.$router,a=this.$route,c=f(this.to,a,this.append),u=o.match(c),s=u.redirectedFrom||u.fullPath,p=o.history.base,h=p?n(p+s):s,d={},y=this.activeClass||o.options.linkActiveClass||"router-link-active";d[y]=this.exact?r(a,u):i(a,u);var v={class:d,on:{click:function(t){t.preventDefault(),e.replace?o.replace(c):o.push(c)}}};if("a"===this.tag)v.attrs={href:h};else{var m=l(this.$slots.default);if(m){var g=m.data||(m.data={}),w=g.attrs||(g.attrs={});w.href=h}}return t(this.tag,v,this.$slots.default)}},X=v(function(t){t.exports=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)}}),Y=y(X),W=Object.freeze({default:Y}),G=v(function(t){function e(t){for(var e,n=[],r=0,o=0,i="";null!=(e=m.exec(t));){var a=e[0],u=e[1],s=e.index;if(i+=t.slice(o,s),o=s+a.length,u)i+=u[1];else{var p=t[o],h=e[2],f=e[3],l=e[4],d=e[5],y=e[6],v=e[7];i&&(n.push(i),i="");var g=null!=h&&null!=p&&p!==h,w="+"===y||"*"===y,b="?"===y||"*"===y,x=e[2]||"/",k=l||d||(v?".*":"[^"+x+"]+?");n.push({name:f||r++,prefix:h||"",delimiter:x,optional:b,repeat:w,partial:g,asterisk:!!v,pattern:c(k)})}}return o<t.length&&(i+=t.substr(o)),i&&n.push(i),n}function n(t){return i(e(t))}function r(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function o(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function i(t){for(var e=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(e[n]=new RegExp("^(?:"+t[n].pattern+")$"));return function(n,i){for(var a="",c=n||{},u=i||{},s=u.pretty?r:encodeURIComponent,p=0;p<t.length;p++){var h=t[p];if("string"!=typeof h){var f,l=c[h.name];if(null==l){if(h.optional){h.partial&&(a+=h.prefix);continue}throw new TypeError('Expected "'+h.name+'" to be defined')}if(v(l)){if(!h.repeat)throw new TypeError('Expected "'+h.name+'" to not repeat, but received `'+JSON.stringify(l)+"`");if(0===l.length){if(h.optional)continue;throw new TypeError('Expected "'+h.name+'" to not be empty')}for(var d=0;d<l.length;d++){if(f=s(l[d]),!e[p].test(f))throw new TypeError('Expected all "'+h.name+'" to match "'+h.pattern+'", but received `'+JSON.stringify(f)+"`");a+=(0===d?h.prefix:h.delimiter)+f}}else{if(f=h.asterisk?o(l):s(l),!e[p].test(f))throw new TypeError('Expected "'+h.name+'" to match "'+h.pattern+'", but received "'+f+'"');a+=h.prefix+f}}else a+=h}return a}}function a(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function c(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function u(t,e){return t.keys=e,t}function s(t){return t.sensitive?"":"i"}function p(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return u(t,e)}function h(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(d(t[o],e,n).source);var i=new RegExp("(?:"+r.join("|")+")",s(n));return u(i,e)}function f(t,n,r){for(var o=e(t),i=l(o,r),a=0;a<o.length;a++)"string"!=typeof o[a]&&n.push(o[a]);return u(i,n)}function l(t,e){e=e||{};for(var n=e.strict,r=e.end!==!1,o="",i=t[t.length-1],c="string"==typeof i&&/\/$/.test(i),u=0;u<t.length;u++){var p=t[u];if("string"==typeof p)o+=a(p);else{var h=a(p.prefix),f="(?:"+p.pattern+")";p.repeat&&(f+="(?:"+h+f+")*"),f=p.optional?p.partial?h+"("+f+")?":"(?:"+h+"("+f+"))?":h+"("+f+")",o+=f}}return n||(o=(c?o.slice(0,-2):o)+"(?:\\/(?=$))?"),o+=r?"$":n&&c?"":"(?=\\/|$)",new RegExp("^"+o,s(e))}function d(t,e,n){return e=e||[],v(e)?n||(n={}):(n=e,e=[]),t instanceof RegExp?p(t,e):v(t)?h(t,e,n):f(t,e,n)}var v=y(W);t.exports=d,t.exports.parse=e,t.exports.compile=n,t.exports.tokensToFunction=i,t.exports.tokensToRegExp=l;var m=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g")}),K=y(G),Q=Object.create(null),Z=Object.create(null),tt="undefined"!=typeof window,et=tt&&function(){var t=window.navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history)}(),nt=function(t,e){this.router=t,this.base=S(e),this.current=t.match("/"),this.pending=null,this.transitionTo(this.getLocation())};nt.prototype.listen=function(t){this.cb=t},nt.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r)})},nt.prototype.confirmTransition=function(t,e){var n=this;if(!r(t,this.current)){var o=_(this.current.matched,t.matched),i=o.deactivated,a=o.activated,c=[].concat($(i),this.router.beforeHooks,a.map(function(t){return t.beforeEnter})).filter(function(t){return t});this.pending=t;var u=function(t){return n.push(t)};A(c,function(e,n){e(t,u,n)},function(){r(t,n.pending)&&(n.pending=null,e(t))})}},nt.prototype.updateRoute=function(t){this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(e){e&&e(t)})},nt.prototype.getLocation=function(){return"/"};var rt=function(){return String(Date.now())},ot=rt(),it=function(t){function e(e,r){var o=this;t.call(this,e,r);var i=n(this.base+this.current.fullPath);this.getLocation()!==i&&B(i);var a=e.options.scrollBehavior;window.addEventListener("popstate",function(t){ot=t.state&&t.state.key;var e=o.current;o.transitionTo(o.getLocation(),function(t){a&&o.handleScroll(t,e,!0)})}),a&&window.addEventListener("scroll",function(){R(ot)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(e){var r=this,o=this.current;t.prototype.transitionTo.call(this,e,function(t){V(n(r.base+t.fullPath)),r.handleScroll(t,o,!1)})},e.prototype.replace=function(e){var r=this,o=this.current;t.prototype.transitionTo.call(this,e,function(t){B(n(r.base+t.fullPath)),r.handleScroll(t,o,!1)})},e.prototype.getLocation=function(){return I(this.base)},e.prototype.handleScroll=function(t,e,n){var r=this.router;if(r.app){var o=r.options.scrollBehavior;o&&(c("function"==typeof o,"scrollBehavior must be a function"),r.app.$nextTick(function(){var r=T(ot),i=o(t,e,n?r:null);if(i){var a="object"==typeof i;if(a&&i.selector){var c=document.querySelector(i.selector);c?r=q(c):C(i)&&(r=L(i))}else a&&C(i)&&(r=L(i));r&&window.scrollTo(r.x,r.y)}}))}},e}(nt),at=function(t){function e(e,n,r){var o=this;t.call(this,e,n),r&&this.checkFallback()||(H(),U()!==this.current.fullPath&&M(this.current.fullPath),window.addEventListener("hashchange",function(){o.onHashChange()}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkFallback=function(){var t=I(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.onHashChange=function(){H()&&this.transitionTo(this.getLocation(),function(t){M(t.fullPath)})},e.prototype.push=function(e){t.prototype.transitionTo.call(this,e,function(t){z(t.fullPath)})},e.prototype.replace=function(e){t.prototype.transitionTo.call(this,e,function(t){M(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e.prototype.getLocation=function(){return U()},e}(nt),ct=function(t){function e(e){t.call(this,e),this.stack=[this.current],this.index=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++})},e.prototype.replace=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!this.stack,!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e.prototype.setInitialRoute=function(t){this.current=t,this.stack=[this.current],this.index=0},e}(nt),ut=function(t){void 0===t&&(t={}),this.app=null,this.options=t,this.beforeHooks=[],this.afterHooks=[],this.match=b(t.routes||[]);var e=t.mode||"hash";this.fallback="history"===e&&!et,this.fallback&&(e="hash"),tt||(e="abstract"),this.mode=e};return ut.prototype.init=function(t){var e=this;c(d.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before creating root instance.");var n=this,r=n.mode,o=n.options,i=n.fallback;switch(r){case"history":this.history=new it(this,o.base);break;case"hash":this.history=new at(this,o.base,i);break;case"abstract":this.history=new ct(this);break;default:c(!1,"invalid mode: "+r)}this.app=t,this.history.listen(function(t){e.app._route=t})},ut.prototype.beforeEach=function(t){this.beforeHooks.push(t)},ut.prototype.afterEach=function(t){this.afterHooks.push(t)},ut.prototype.push=function(t){this.history.push(t)},ut.prototype.replace=function(t){this.history.replace(t)},ut.prototype.go=function(t){this.history.go(t)},ut.prototype.back=function(){this.go(-1)},ut.prototype.forward=function(){this.go(1)},ut.prototype.setInitialLocation=function(t){this.history instanceof ct&&this.history.setInitialRoute(this.match(t))},ut.install=d,tt&&window.Vue&&window.Vue.use(ut),ut}); |
{ | ||
"name": "vue-router", | ||
"version": "2.0.0-beta.1", | ||
"version": "2.0.0-beta.2", | ||
"description": "Official router for Vue.js 2.0", | ||
@@ -5,0 +5,0 @@ "author": "Evan You", |
@@ -107,3 +107,3 @@ /* @flow */ | ||
} else { | ||
warn(`invalid redirect option: ${JSON.stringify(redirect)}`) | ||
warn(false, `invalid redirect option: ${JSON.stringify(redirect)}`) | ||
return createRouteContext(null, location) | ||
@@ -178,3 +178,3 @@ } | ||
} catch (e) { | ||
assert(`missing param for ${routeMsg}: ${e.message}`) | ||
assert(false, `missing param for ${routeMsg}: ${e.message}`) | ||
return '' | ||
@@ -181,0 +181,0 @@ } |
@@ -54,3 +54,3 @@ /* @flow */ | ||
// global before hooks | ||
nomralizeGuards(this.router.options.beforeEach), | ||
this.router.beforeHooks, | ||
// activate guards | ||
@@ -78,3 +78,3 @@ activated.map(m => m.beforeEnter) | ||
this.cb && this.cb(route) | ||
nomralizeGuards(this.router.options.afterEach).forEach(hook => { | ||
this.router.afterHooks.forEach(hook => { | ||
hook && hook(route) | ||
@@ -127,12 +127,2 @@ }) | ||
function nomralizeGuards (guards?: Function | Array<?Function>): Array<?Function> { | ||
if (!guards) { | ||
return [] | ||
} | ||
if (typeof guards === 'function') { | ||
return [guards] | ||
} | ||
return guards | ||
} | ||
function extractLeaveGuards (matched: Array<RouteRecord>): Array<?Function> { | ||
@@ -139,0 +129,0 @@ return Array.prototype.concat.apply([], matched.map(m => { |
@@ -7,2 +7,9 @@ /* @flow */ | ||
import { History } from './base' | ||
import { | ||
saveScrollPosition, | ||
getScrollPosition, | ||
isValidPosition, | ||
normalizePosotion, | ||
getElementPosition | ||
} from '../util/scroll-position' | ||
@@ -35,3 +42,5 @@ const genKey = () => String(Date.now()) | ||
if (expectScroll) { | ||
window.addEventListener('scroll', saveScrollPosition) | ||
window.addEventListener('scroll', () => { | ||
saveScrollPosition(_key) | ||
}) | ||
} | ||
@@ -74,26 +83,21 @@ } | ||
} | ||
assert(typeof behavior === 'function', `scrollBehavior must be a function`) | ||
let position = getScrollPosition() | ||
const shouldScroll = behavior(to, from, isPop ? position : null) | ||
if (!shouldScroll) { | ||
return | ||
} | ||
// wait until re-render finishes before scrolling | ||
router.app.$nextTick(() => { | ||
let position = getScrollPosition(_key) | ||
const shouldScroll = behavior(to, from, isPop ? position : null) | ||
if (!shouldScroll) { | ||
return | ||
} | ||
const isObject = typeof shouldScroll === 'object' | ||
if (isObject && shouldScroll.x != null && shouldScroll.y != null) { | ||
position = shouldScroll | ||
} else if (isObject && shouldScroll.anchor) { | ||
const el = document.querySelector(to.hash) | ||
if (isObject && shouldScroll.selector) { | ||
const el = document.querySelector(shouldScroll.selector) | ||
if (el) { | ||
const docTop = document.documentElement.getBoundingClientRect().top | ||
const elTop = el.getBoundingClientRect().top | ||
position = { | ||
x: window.scrollX, | ||
y: elTop - docTop | ||
} | ||
position = getElementPosition(el) | ||
} else if (isValidPosition(shouldScroll)) { | ||
position = normalizePosotion(shouldScroll) | ||
} | ||
} else if (isObject && isValidPosition(shouldScroll)) { | ||
position = normalizePosotion(shouldScroll) | ||
} | ||
@@ -127,3 +131,3 @@ | ||
} | ||
saveScrollPosition() | ||
saveScrollPosition(_key) | ||
} catch (e) { | ||
@@ -137,14 +141,1 @@ window.location[replace ? 'assign' : 'replace'](url) | ||
} | ||
function saveScrollPosition () { | ||
if (!_key) return | ||
window.sessionStorage.setItem(_key, JSON.stringify({ | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
})) | ||
} | ||
function getScrollPosition (): ?{ x: number, y: number } { | ||
if (!_key) return | ||
return JSON.parse(window.sessionStorage.getItem(_key)) | ||
} |
@@ -16,20 +16,19 @@ /* @flow */ | ||
options: RouterOptions; | ||
mode: 'hash' | 'history' | 'abstract'; | ||
mode: string; | ||
history: HashHistory | HTML5History | AbstractHistory; | ||
match: Matcher; | ||
fallback: boolean; | ||
beforeHooks: Array<?Function>; | ||
afterHooks: Array<?Function>; | ||
constructor (options: RouterOptions = {}) { | ||
assert( | ||
install.installed, | ||
`not installed. Make sure to call \`Vue.use(VueRouter)\` ` + | ||
`before mounting root instance.` | ||
) | ||
this.app = null | ||
this.options = options | ||
this.beforeHooks = [] | ||
this.afterHooks = [] | ||
this.match = createMatcher(options.routes || []) | ||
let mode = options.mode || 'hash' | ||
const fallback = mode === 'history' && !supportsHistory | ||
if (fallback) { | ||
this.fallback = mode === 'history' && !supportsHistory | ||
if (this.fallback) { | ||
mode = 'hash' | ||
@@ -40,3 +39,13 @@ } | ||
} | ||
this.mode = mode | ||
} | ||
init (app: any /* Vue component instance */) { | ||
assert( | ||
install.installed, | ||
`not installed. Make sure to call \`Vue.use(VueRouter)\` ` + | ||
`before creating root instance.` | ||
) | ||
const { mode, options, fallback } = this | ||
switch (mode) { | ||
@@ -56,4 +65,3 @@ case 'history': | ||
this.mode = mode | ||
this.app = app | ||
this.history.listen(route => { | ||
@@ -64,2 +72,10 @@ this.app._route = route | ||
beforeEach (fn: Function) { | ||
this.beforeHooks.push(fn) | ||
} | ||
afterEach (fn: Function) { | ||
this.afterHooks.push(fn) | ||
} | ||
push (location: RawLocation) { | ||
@@ -66,0 +82,0 @@ this.history.push(location) |
@@ -20,3 +20,3 @@ import View from './components/view' | ||
this._router = this.$options.router | ||
this._router.app = this | ||
this._router.init(this) | ||
Vue.util.defineReactive(this, '_route', this._router.history.current) | ||
@@ -23,0 +23,0 @@ } |
@@ -1,2 +0,4 @@ | ||
export function assert (condition, message) { | ||
/* @flow */ | ||
export function assert (condition: any, message: string) { | ||
if (!condition) { | ||
@@ -7,3 +9,3 @@ throw new Error(`[vue-router] ${message}`) | ||
export function warn (condition, message) { | ||
export function warn (condition: any, message: string) { | ||
if (!condition) { | ||
@@ -10,0 +12,0 @@ typeof console !== 'undefined' && console.warn(`[vue-router] ${message}`) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
93299
22
2546
0
16
0