vue-router
Advanced tools
Comparing version 2.0.1 to 2.0.2
/** | ||
* vue-router v2.0.1 | ||
* vue-router v2.0.2 | ||
* (c) 2016 Evan You | ||
@@ -60,2 +60,5 @@ * @license MIT | ||
} | ||
hooks.prepatch = function (oldVnode, vnode) { | ||
matched.instances[name] = vnode.child | ||
} | ||
hooks.destroy = function (vnode) { | ||
@@ -187,3 +190,3 @@ if (matched.instances[name] === vnode.child) { | ||
function parseQuery (query) { | ||
var res = Object.create(null) | ||
var res = {} | ||
@@ -330,3 +333,3 @@ query = query.trim().replace(/^(\?|#|&)/, '') | ||
return ( | ||
current.path.indexOf(target.path) === 0 && | ||
current.path.indexOf(target.path.replace(/\/$/, '')) === 0 && | ||
(!target.hash || current.hash === target.hash) && | ||
@@ -404,6 +407,6 @@ queryIncludes(current.query, target.query) | ||
var to = normalizeLocation(this.to, current, this.append) | ||
var resolved = router.match(to) | ||
var resolved = router.match(to, current) | ||
var fullPath = resolved.redirectedFrom || resolved.fullPath | ||
var base = router.history.base | ||
var href = base ? cleanPath(base + fullPath) : fullPath | ||
var href = createHref(base, fullPath, router.mode) | ||
var classes = {} | ||
@@ -427,2 +430,7 @@ var activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active' | ||
if (e.button !== 0) { return } | ||
// don't redirect if `target="_blank"` | ||
/* istanbul ignore if */ | ||
var target = e.target.getAttribute('target') | ||
if (/\b_blank\b/i.test(target)) { return } | ||
e.preventDefault() | ||
@@ -448,5 +456,8 @@ if (this$1.replace) { | ||
if (a) { | ||
var aData = a.data || (a.data = {}) | ||
// in case the <a> is a static node | ||
a.isStatic = false | ||
var extend = _Vue.util.extend | ||
var aData = a.data = extend({}, a.data) | ||
aData.on = on | ||
var aAttrs = aData.attrs || (aData.attrs = {}) | ||
var aAttrs = a.data.attrs = extend({}, a.data.attrs) | ||
aAttrs.href = href | ||
@@ -478,2 +489,9 @@ } else { | ||
function createHref (base, fullPath, mode) { | ||
var path = mode === 'hash' ? '/#' + fullPath : fullPath | ||
return base ? cleanPath(base + path) : path | ||
} | ||
var _Vue | ||
function install (Vue) { | ||
@@ -483,2 +501,4 @@ if (install.installed) { return } | ||
_Vue = Vue | ||
Object.defineProperty(Vue.prototype, '$router', { | ||
@@ -504,2 +524,6 @@ get: function get () { return this.$root._router } | ||
Vue.component('router-link', Link) | ||
var strats = Vue.config.optionMergeStrategies | ||
// use the same hook merging strategy for route hooks | ||
strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created | ||
} | ||
@@ -543,6 +567,7 @@ | ||
* | ||
* @param {string} str | ||
* @param {string} str | ||
* @param {Object=} options | ||
* @return {!Array} | ||
*/ | ||
function parse (str) { | ||
function parse (str, options) { | ||
var tokens = [] | ||
@@ -552,2 +577,3 @@ var key = 0 | ||
var path = '' | ||
var defaultDelimiter = options && options.delimiter || '/' | ||
var res | ||
@@ -585,4 +611,4 @@ | ||
var optional = modifier === '?' || modifier === '*' | ||
var delimiter = res[2] || '/' | ||
var pattern = capture || group || (asterisk ? '.*' : '[^' + delimiter + ']+?') | ||
var delimiter = res[2] || defaultDelimiter | ||
var pattern = capture || group | ||
@@ -597,3 +623,3 @@ tokens.push({ | ||
asterisk: !!asterisk, | ||
pattern: escapeGroup(pattern) | ||
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?') | ||
}) | ||
@@ -619,6 +645,7 @@ } | ||
* @param {string} str | ||
* @param {Object=} options | ||
* @return {!function(Object=, Object=)} | ||
*/ | ||
function compile (str) { | ||
return tokensToFunction(parse(str)) | ||
function compile (str, options) { | ||
return tokensToFunction(parse(str, options)) | ||
} | ||
@@ -834,13 +861,3 @@ | ||
function stringToRegexp (path, keys, options) { | ||
var tokens = parse(path) | ||
var re = tokensToRegExp(tokens, options) | ||
// Attach keys back to the regexp. | ||
for (var i = 0; i < tokens.length; i++) { | ||
if (typeof tokens[i] !== 'string') { | ||
keys.push(tokens[i]) | ||
} | ||
} | ||
return attachKeys(re, keys) | ||
return tokensToRegExp(parse(path, options), keys, options) | ||
} | ||
@@ -851,7 +868,13 @@ | ||
* | ||
* @param {!Array} tokens | ||
* @param {Object=} options | ||
* @param {!Array} tokens | ||
* @param {(Array|Object)=} keys | ||
* @param {Object=} options | ||
* @return {!RegExp} | ||
*/ | ||
function tokensToRegExp (tokens, options) { | ||
function tokensToRegExp (tokens, keys, options) { | ||
if (!isarray(keys)) { | ||
options = /** @type {!Object} */ (keys || options) | ||
keys = [] | ||
} | ||
options = options || {} | ||
@@ -862,4 +885,2 @@ | ||
var route = '' | ||
var lastToken = tokens[tokens.length - 1] | ||
var endsWithSlash = typeof lastToken === 'string' && /\/$/.test(lastToken) | ||
@@ -876,2 +897,4 @@ // Iterate over the tokens and create our regexp string. | ||
keys.push(token) | ||
if (token.repeat) { | ||
@@ -895,2 +918,5 @@ capture += '(?:' + prefix + capture + ')*' | ||
var delimiter = escapeString(options.delimiter || '/') | ||
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter | ||
// In non-strict mode we allow a slash at the end of match. If the path to | ||
@@ -901,3 +927,3 @@ // match already ends with a slash, we remove it for consistency. The slash | ||
if (!strict) { | ||
route = (endsWithSlash ? route.slice(0, -2) : route) + '(?:\\/(?=$))?' | ||
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?' | ||
} | ||
@@ -910,6 +936,6 @@ | ||
// possible by using a positive lookahead to the end or next path segment. | ||
route += strict && endsWithSlash ? '' : '(?=\\/|$)' | ||
route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)' | ||
} | ||
return new RegExp('^' + route, flags(options)) | ||
return attachKeys(new RegExp('^' + route, flags(options)), keys) | ||
} | ||
@@ -930,11 +956,9 @@ | ||
function pathToRegexp (path, keys, options) { | ||
keys = keys || [] | ||
if (!isarray(keys)) { | ||
options = /** @type {!Object} */ (keys) | ||
options = /** @type {!Object} */ (keys || options) | ||
keys = [] | ||
} else if (!options) { | ||
options = {} | ||
} | ||
options = options || {} | ||
if (path instanceof RegExp) { | ||
@@ -1005,3 +1029,3 @@ return regexpToRegexp(path, /** @type {!Array} */ (keys)) | ||
if (route.alias) { | ||
if (route.alias !== undefined) { | ||
if (Array.isArray(route.alias)) { | ||
@@ -1017,3 +1041,9 @@ route.alias.forEach(function (alias) { | ||
pathMap[record.path] = record | ||
if (name) { nameMap[name] = record } | ||
if (name) { | ||
if (!nameMap[name]) { | ||
nameMap[name] = record | ||
} else { | ||
warn(false, ("Duplicate named routes definition: { name: \"" + name + "\", path: \"" + (record.path) + "\" }")) | ||
} | ||
} | ||
} | ||
@@ -1049,2 +1079,15 @@ | ||
var record = nameMap[name] | ||
if (typeof location.params !== 'object') { | ||
location.params = {} | ||
} | ||
if (currentRoute && typeof currentRoute.params === 'object') { | ||
for (var key in currentRoute.params) { | ||
if (!(key in location.params)) { | ||
location.params[key] = currentRoute.params[key] | ||
} | ||
} | ||
} | ||
if (record) { | ||
@@ -1305,3 +1348,3 @@ location.path = fillParams(record.path, location.params, ("named route \"" + name + "\"")) | ||
// next(false) -> abort navigation, ensure current URL | ||
this$1.ensureURL() | ||
this$1.ensureURL(true) | ||
} else if (typeof to === 'string' || typeof to === 'object') { | ||
@@ -1380,13 +1423,33 @@ // next('/') or next({ path: '/' }) -> redirect | ||
function extractGuard ( | ||
def, | ||
key | ||
) { | ||
if (typeof def !== 'function') { | ||
// extend now so that global mixins are applied. | ||
def = _Vue.extend(def) | ||
} | ||
return def.options[key] | ||
} | ||
function extractLeaveGuards (matched) { | ||
return flatMapComponents(matched, function (def, instance) { | ||
var guard = def && def.beforeRouteLeave | ||
return flatten(flatMapComponents(matched, function (def, instance) { | ||
var guard = extractGuard(def, 'beforeRouteLeave') | ||
if (guard) { | ||
return function routeLeaveGuard () { | ||
return guard.apply(instance, arguments) | ||
} | ||
return Array.isArray(guard) | ||
? guard.map(function (guard) { return wrapLeaveGuard(guard, instance); }) | ||
: wrapLeaveGuard(guard, instance) | ||
} | ||
}).reverse() | ||
}).reverse()) | ||
} | ||
function wrapLeaveGuard ( | ||
guard, | ||
instance | ||
) { | ||
return function routeLeaveGuard () { | ||
return guard.apply(instance, arguments) | ||
} | ||
} | ||
function extractEnterGuards ( | ||
@@ -1397,25 +1460,42 @@ matched, | ||
) { | ||
return flatMapComponents(matched, function (def, _, match, key) { | ||
var guard = def && def.beforeRouteEnter | ||
return flatten(flatMapComponents(matched, function (def, _, match, key) { | ||
var guard = extractGuard(def, 'beforeRouteEnter') | ||
if (guard) { | ||
return function routeEnterGuard (to, from, next) { | ||
return guard(to, from, function (cb) { | ||
next(cb) | ||
if (typeof cb === 'function') { | ||
cbs.push(function () { | ||
// #750 | ||
// if a router-view is wrapped with an out-in transition, | ||
// the instance may not have been registered at this time. | ||
// we will need to poll for registration until current route | ||
// is no longer valid. | ||
poll(cb, match.instances, key, isValid) | ||
}) | ||
} | ||
return Array.isArray(guard) | ||
? guard.map(function (guard) { return wrapEnterGuard(guard, cbs, match, key, isValid); }) | ||
: wrapEnterGuard(guard, cbs, match, key, isValid) | ||
} | ||
})) | ||
} | ||
function wrapEnterGuard ( | ||
guard, | ||
cbs, | ||
match, | ||
key, | ||
isValid | ||
) { | ||
return function routeEnterGuard (to, from, next) { | ||
return guard(to, from, function (cb) { | ||
next(cb) | ||
if (typeof cb === 'function') { | ||
cbs.push(function () { | ||
// #750 | ||
// if a router-view is wrapped with an out-in transition, | ||
// the instance may not have been registered at this time. | ||
// we will need to poll for registration until current route | ||
// is no longer valid. | ||
poll(cb, match.instances, key, isValid) | ||
}) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
function poll (cb, instances, key, isValid) { | ||
function poll ( | ||
cb, // somehow flow cannot infer this is a function | ||
instances, | ||
key, | ||
isValid | ||
) { | ||
if (instances[key]) { | ||
@@ -1462,3 +1542,3 @@ cb(instances[key]) | ||
) { | ||
return Array.prototype.concat.apply([], matched.map(function (m) { | ||
return flatten(matched.map(function (m) { | ||
return Object.keys(m.components).map(function (key) { return fn( | ||
@@ -1472,10 +1552,16 @@ m.components[key], | ||
function flatten (arr) { | ||
return Array.prototype.concat.apply([], arr) | ||
} | ||
/* */ | ||
var positionStore = Object.create(null) | ||
function saveScrollPosition (key) { | ||
if (!key) { return } | ||
window.sessionStorage.setItem(key, JSON.stringify({ | ||
positionStore[key] = { | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
})) | ||
} | ||
} | ||
@@ -1485,3 +1571,3 @@ | ||
if (!key) { return } | ||
return JSON.parse(window.sessionStorage.getItem(key)) | ||
return positionStore[key] | ||
} | ||
@@ -1525,4 +1611,2 @@ | ||
this.transitionTo(getLocation(this.base)) | ||
var expectScroll = router.options.scrollBehavior | ||
@@ -1574,5 +1658,6 @@ window.addEventListener('popstate', function (e) { | ||
HTML5History.prototype.ensureURL = function ensureURL () { | ||
HTML5History.prototype.ensureURL = function ensureURL (push) { | ||
if (getLocation(this.base) !== this.current.fullPath) { | ||
replaceState(cleanPath(this.base + this.current.fullPath)) | ||
var current = cleanPath(this.base + this.current.fullPath) | ||
push ? pushState(current) : replaceState(current) | ||
} | ||
@@ -1655,4 +1740,2 @@ }; | ||
function HashHistory (router, base, fallback) { | ||
var this$1 = this; | ||
History.call(this, router, base) | ||
@@ -1666,7 +1749,2 @@ | ||
ensureSlash() | ||
this.transitionTo(getHash(), function () { | ||
window.addEventListener('hashchange', function () { | ||
this$1.onHashChange() | ||
}) | ||
}) | ||
} | ||
@@ -1713,5 +1791,6 @@ | ||
HashHistory.prototype.ensureURL = function ensureURL () { | ||
if (getHash() !== this.current.fullPath) { | ||
replaceHash(this.current.fullPath) | ||
HashHistory.prototype.ensureURL = function ensureURL (push) { | ||
var current = this.current.fullPath | ||
if (getHash() !== current) { | ||
push ? pushHash(current) : replaceHash(current) | ||
} | ||
@@ -1823,2 +1902,16 @@ }; | ||
this.mode = mode | ||
switch (mode) { | ||
case 'history': | ||
this.history = new HTML5History(this, options.base) | ||
break | ||
case 'hash': | ||
this.history = new HashHistory(this, options.base, this.fallback) | ||
break | ||
case 'abstract': | ||
this.history = new AbstractHistory(this) | ||
break | ||
default: | ||
assert(false, ("invalid mode: " + mode)) | ||
} | ||
}; | ||
@@ -1843,21 +1936,15 @@ | ||
var ref = this; | ||
var mode = ref.mode; | ||
var options = ref.options; | ||
var fallback = ref.fallback; | ||
switch (mode) { | ||
case 'history': | ||
this.history = new HTML5History(this, options.base) | ||
break | ||
case 'hash': | ||
this.history = new HashHistory(this, options.base, fallback) | ||
break | ||
case 'abstract': | ||
this.history = new AbstractHistory(this) | ||
break | ||
default: | ||
assert(false, ("invalid mode: " + mode)) | ||
var history = this.history | ||
if (history instanceof HTML5History) { | ||
history.transitionTo(getLocation(history.base)) | ||
} else if (history instanceof HashHistory) { | ||
history.transitionTo(getHash(), function () { | ||
window.addEventListener('hashchange', function () { | ||
history.onHashChange() | ||
}) | ||
}) | ||
} | ||
this.history.listen(function (route) { | ||
history.listen(function (route) { | ||
this$1.app._route = route | ||
@@ -1864,0 +1951,0 @@ }) |
/** | ||
* vue-router v2.0.1 | ||
* vue-router v2.0.2 | ||
* (c) 2016 Evan You | ||
* @license MIT | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if("/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i<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){if(!t)throw new Error("[vue-router] "+e)}function o(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function i(t,e){if(void 0===e&&(e={}),t){var n;try{n=a(t)}catch(t){o(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function a(t){var e=Object.create(null);return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=ct(n.shift()),o=n.length>0?ct(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return ut(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(ut(e)):r.push(ut(e)+"="+ut(t)))}),r.join("&")}return ut(e)+"="+ut(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function c(t,e,n){var r={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:p(e),matched:t?s(t):[]};return n&&(r.redirectedFrom=p(n)),Object.freeze(r)}function s(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function p(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+u(n)+r}function f(t,e){return e===st?t===e:!!e&&(t.path&&e.path?t.path.replace(pt,"")===e.path.replace(pt,"")&&t.hash===e.hash&&h(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&h(t.query,e.query)&&h(t.params,e.params)))}function h(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function l(t,e){return 0===t.path.indexOf(e.path)&&(!e.hash||t.hash===e.hash)&&d(t.query,e.query)}function d(t,e){for(var n in e)if(!(n in t))return!1;return!0}function y(n,r,o){var a="string"==typeof n?{path:n}:n;if(a.name||a._normalized)return a;var u=e(a.path||""),c=r&&r.path||"/",s=u.path?t(u.path,c,o):r&&r.path||"/",p=i(u.query,a.query),f=a.hash||u.hash;return f&&"#"!==f.charAt(0)&&(f="#"+f),{_normalized:!0,path:s,query:p,hash:f}}function v(t){if(t)for(var e,n=0;n<t.length;n++){if(e=t[n],"a"===e.tag)return e;if(e.children&&(e=v(e.children)))return e}}function m(t){m.installed||(m.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",at),t.component("router-link",ht))}function g(t){for(var e,n=[],r=0,o=0,i="";null!=(e=bt.exec(t));){var a=e[0],u=e[1],c=e.index;if(i+=t.slice(o,c),o=c+a.length,u)i+=u[1];else{var s=t[o],p=e[2],f=e[3],h=e[4],l=e[5],d=e[6],y=e[7];i&&(n.push(i),i="");var v=null!=p&&null!=s&&s!==p,m="+"===d||"*"===d,g="?"===d||"*"===d,w=e[2]||"/",b=h||l||(y?".*":"[^"+w+"]+?");n.push({name:f||r++,prefix:p||"",delimiter:w,optional:g,repeat:m,partial:v,asterisk:!!y,pattern:E(b)})}}return o<t.length&&(i+=t.substr(o)),i&&n.push(i),n}function w(t){return k(g(t))}function b(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function x(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function k(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,r){for(var o="",i=n||{},a=r||{},u=a.pretty?b:encodeURIComponent,c=0;c<t.length;c++){var s=t[c];if("string"!=typeof s){var p,f=i[s.name];if(null==f){if(s.optional){s.partial&&(o+=s.prefix);continue}throw new TypeError('Expected "'+s.name+'" to be defined')}if(dt(f)){if(!s.repeat)throw new TypeError('Expected "'+s.name+'" to not repeat, but received `'+JSON.stringify(f)+"`");if(0===f.length){if(s.optional)continue;throw new TypeError('Expected "'+s.name+'" to not be empty')}for(var h=0;h<f.length;h++){if(p=u(f[h]),!e[c].test(p))throw new TypeError('Expected all "'+s.name+'" to match "'+s.pattern+'", but received `'+JSON.stringify(p)+"`");o+=(0===h?s.prefix:s.delimiter)+p}}else{if(p=s.asterisk?x(f):u(f),!e[c].test(p))throw new TypeError('Expected "'+s.name+'" to match "'+s.pattern+'", but received "'+p+'"');o+=s.prefix+p}}else o+=s}return o}}function O(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function E(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function R(t,e){return t.keys=e,t}function j(t){return t.sensitive?"":"i"}function S(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 R(t,e)}function $(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(T(t[o],e,n).source);var i=new RegExp("(?:"+r.join("|")+")",j(n));return R(i,e)}function A(t,e,n){for(var r=g(t),o=_(r,n),i=0;i<r.length;i++)"string"!=typeof r[i]&&e.push(r[i]);return R(o,e)}function _(t,e){e=e||{};for(var n=e.strict,r=e.end!==!1,o="",i=t[t.length-1],a="string"==typeof i&&/\/$/.test(i),u=0;u<t.length;u++){var c=t[u];if("string"==typeof c)o+=O(c);else{var s=O(c.prefix),p="(?:"+c.pattern+")";c.repeat&&(p+="(?:"+s+p+")*"),p=c.optional?c.partial?s+"("+p+")?":"(?:"+s+"("+p+"))?":s+"("+p+")",o+=p}}return n||(o=(a?o.slice(0,-2):o)+"(?:\\/(?=$))?"),o+=r?"$":n&&a?"":"(?=\\/|$)",new RegExp("^"+o,j(e))}function T(t,e,n){return e=e||[],dt(e)?n||(n={}):(n=e,e=[]),t instanceof RegExp?S(t,e):dt(t)?$(t,e,n):A(t,e,n)}function q(t){var e=Object.create(null),n=Object.create(null);return t.forEach(function(t){C(e,n,t)}),{pathMap:e,nameMap:n}}function C(t,e,n,o,i){var a=n.path,u=n.name;r(null!=a,'"path" is required in a route configuration.');var c={path:P(a,o),components:n.components||{default:n.component},instances:{},name:u,parent:o,matchAs:i,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{}};n.children&&n.children.forEach(function(n){C(t,e,n,c)}),n.alias&&(Array.isArray(n.alias)?n.alias.forEach(function(n){C(t,e,{path:n},o,c.path)}):C(t,e,{path:n.alias},o,c.path)),t[c.path]=c,u&&(e[u]=c)}function P(t,e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:n(e.path+"/"+t)}function U(t){function e(t,e,n){var r=y(t,e),o=r.name;if(o){var i=p[o];if(i)return r.path=V(i.path,r.params,'named route "'+o+'"'),a(i,r,n)}else if(r.path){r.params={};for(var u in s)if(L(u,r.params,r.path))return a(s[u],r,n)}return a(null,r)}function n(t,n){var i=t.redirect,u="function"==typeof i?i(c(t,n)):i;if("string"==typeof u&&(u={path:u}),!u||"object"!=typeof u)return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n);var s=u,f=s.name,h=s.path,l=n.query,d=n.hash,y=n.params;if(l=s.hasOwnProperty("query")?s.query:l,d=s.hasOwnProperty("hash")?s.hash:d,y=s.hasOwnProperty("params")?s.params:y,f){var v=p[f];return r(v,'redirect failed: named route "'+f+'" not found.'),e({_normalized:!0,name:f,query:l,hash:d,params:y},void 0,n)}if(h){var m=B(h,t),g=V(m,y,'redirect route with path "'+m+'"');return e({_normalized:!0,path:g,query:l,hash:d},void 0,n)}return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n)}function i(t,n,r){var o=V(r,n.params,'aliased route with path "'+r+'"'),i=e({_normalized:!0,path:o});if(i){var u=i.matched,c=u[u.length-1];return n.params=i.params,a(c,n)}return a(null,n)}function a(t,e,r){return t&&t.redirect?n(t,r||e):t&&t.matchAs?i(t,e,t.matchAs):c(t,e,r)}var u=q(t),s=u.pathMap,p=u.nameMap;return e}function L(t,e,n){var r,o,i=xt[t];i?(r=i.keys,o=i.regexp):(r=[],o=yt(t,r),xt[t]={keys:r,regexp:o});var a=n.match(o);if(!a)return!1;if(!e)return!0;for(var u=1,c=a.length;u<c;++u){var s=r[u-1],p="string"==typeof a[u]?decodeURIComponent(a[u]):a[u];s&&(e[s.name]=p)}return!0}function V(t,e,n){try{var o=kt[t]||(kt[t]=yt.compile(t));return o(e||{},{pretty:!0})}catch(t){return r(!1,"missing param for "+n+": "+t.message),""}}function B(e,n){return t(e,n.parent?n.parent.path:"/",!0)}function H(t,e,n){var r=function(o){o>=t.length?n():t[o]?e(t[o],function(){r(o+1)}):r(o+1)};r(0)}function I(t){if(!t)if(Ot){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function M(t,e){var n,r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{activated:e.slice(n),deactivated:t.slice(n)}}function z(t){return D(t,function(t,e){var n=t&&t.beforeRouteLeave;if(n)return function(){return n.apply(e,arguments)}}).reverse()}function F(t,e,n){return D(t,function(t,r,o,i){var a=t&&t.beforeRouteEnter;if(a)return function(t,r,u){return a(t,r,function(t){u(t),"function"==typeof t&&e.push(function(){J(t,o.instances,i,n)})})}})}function J(t,e,n,r){e[n]?t(e[n]):r()&&setTimeout(function(){J(t,e,n,r)},16)}function N(t){return D(t,function(t,e,n,r){if("function"==typeof t&&!t.options)return function(e,i,a){var u=function(t){n.components[r]=t,a()},c=function(t){o(!1,"Failed to resolve async component "+r+": "+t),a(!1)},s=t(u,c);s&&"function"==typeof s.then&&s.then(u,c)}})}function D(t,e){return Array.prototype.concat.apply([],t.map(function(t){return Object.keys(t.components).map(function(n){return e(t.components[n],t.instances[n],t,n)})}))}function K(t){t&&window.sessionStorage.setItem(t,JSON.stringify({x:window.pageXOffset,y:window.pageYOffset}))}function X(t){if(t)return JSON.parse(window.sessionStorage.getItem(t))}function Y(t){var e=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top}}function W(t){return Q(t.x)||Q(t.y)}function G(t){return{x:Q(t.x)?t.x:window.pageXOffset,y:Q(t.y)?t.y:window.pageYOffset}}function Q(t){return"number"==typeof t}function Z(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 tt(t,e){var n=window.history;try{e?n.replaceState({key:St},"",t):(St=jt(),n.pushState({key:St},"",t)),K(St)}catch(n){window.location[e?"assign":"replace"](t)}}function et(t){tt(t,!0)}function nt(){var t=rt();return"/"===t.charAt(0)||(it("/"+t),!1)}function rt(){var t=window.location.href,e=t.indexOf("#");return e===-1?"":t.slice(e+1)}function ot(t){window.location.hash=t}function it(t){var e=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,e>=0?e:0)+"#"+t)}var at={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,u=o._routerViewCache||(o._routerViewCache={}),c=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&c++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=c;var p=a.matched[c];if(!p)return t();var f=n.name,h=s?u[f]:u[f]=p.components[f];if(!s){var l=i.hook||(i.hook={});l.init=function(t){p.instances[f]=t.child},l.destroy=function(t){p.instances[f]===t.child&&(p.instances[f]=void 0)}}return t(h,i,r)}},ut=encodeURIComponent,ct=decodeURIComponent,st=c(null,{path:"/"}),pt=/\/$/,ft=[String,Object],ht={name:"router-link",props:{to:{type:ft,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,r=this.$router,o=this.$route,i=y(this.to,o,this.append),a=r.match(i),u=a.redirectedFrom||a.fullPath,s=r.history.base,p=s?n(s+u):u,h={},d=this.activeClass||r.options.linkActiveClass||"router-link-active",m=i.path?c(null,i):a;h[d]=this.exact?f(o,m):l(o,m);var g={click:function(t){t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||0===t.button&&(t.preventDefault(),e.replace?r.replace(i):r.push(i))}},w={class:h};if("a"===this.tag)w.on=g,w.attrs={href:p};else{var b=v(this.$slots.default);if(b){var x=b.data||(b.data={});x.on=g;var k=x.attrs||(x.attrs={});k.href=p}else w.on=g}return t(this.tag,w,this.$slots.default)}},lt=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},dt=lt,yt=T,vt=g,mt=w,gt=k,wt=_,bt=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");yt.parse=vt,yt.compile=mt,yt.tokensToFunction=gt,yt.tokensToRegExp=wt;var xt=Object.create(null),kt=Object.create(null),Ot="undefined"!=typeof window,Et=Ot&&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)}(),Rt=function(t,e){this.router=t,this.base=I(e),this.current=st,this.pending=null};Rt.prototype.listen=function(t){this.cb=t},Rt.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r),n.ensureURL()})},Rt.prototype.confirmTransition=function(t,e){var n=this,r=this.current;if(f(t,r))return void this.ensureURL();var o=M(this.current.matched,t.matched),i=o.deactivated,a=o.activated,u=[].concat(z(i),this.router.beforeHooks,a.map(function(t){return t.beforeEnter}),N(a));this.pending=t;var c=function(e,o){n.pending===t&&e(t,r,function(t){t===!1?n.ensureURL():"string"==typeof t||"object"==typeof t?n.push(t):o(t)})};H(u,c,function(){var r=[],o=F(a,r,function(){return n.current===t});H(o,c,function(){n.pending===t&&(n.pending=null,e(t),n.router.app.$nextTick(function(){r.forEach(function(t){return t()})}))})})},Rt.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(n){n&&n(t,e)})};var jt=function(){return String(Date.now())},St=jt(),$t=function(t){function e(e,n){var r=this;t.call(this,e,n),this.transitionTo(Z(this.base));var o=e.options.scrollBehavior;window.addEventListener("popstate",function(t){St=t.state&&t.state.key;var e=r.current;r.transitionTo(Z(r.base),function(t){o&&r.handleScroll(t,e,!0)})}),o&&window.addEventListener("scroll",function(){K(St)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){tt(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.replace=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){et(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.ensureURL=function(){Z(this.base)!==this.current.fullPath&&et(n(this.base+this.current.fullPath))},e.prototype.handleScroll=function(t,e,n){var o=this.router;if(o.app){var i=o.options.scrollBehavior;i&&(r("function"==typeof i,"scrollBehavior must be a function"),o.app.$nextTick(function(){var r=X(St),o=i(t,e,n?r:null);if(o){var a="object"==typeof o;if(a&&"string"==typeof o.selector){var u=document.querySelector(o.selector);u?r=Y(u):W(o)&&(r=G(o))}else a&&W(o)&&(r=G(o));r&&window.scrollTo(r.x,r.y)}}))}},e}(Rt),At=function(t){function e(e,n,r){var o=this;t.call(this,e,n),r&&this.checkFallback()||(nt(),this.transitionTo(rt(),function(){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=Z(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.onHashChange=function(){nt()&&this.transitionTo(rt(),function(t){it(t.fullPath)})},e.prototype.push=function(t){this.transitionTo(t,function(t){ot(t.fullPath)})},e.prototype.replace=function(t){this.transitionTo(t,function(t){it(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(){rt()!==this.current.fullPath&&it(this.current.fullPath)},e}(Rt),_t=function(t){function e(e){t.call(this,e),this.stack=[],this.index=-1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(t){var e=this;this.transitionTo(t,function(t){e.stack=e.stack.slice(0,e.index+1).concat(t),e.index++})},e.prototype.replace=function(t){var e=this;this.transitionTo(t,function(t){e.stack=e.stack.slice(0,e.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e.prototype.ensureURL=function(){},e}(Rt),Tt=function(t){void 0===t&&(t={}),this.app=null,this.options=t,this.beforeHooks=[],this.afterHooks=[],this.match=U(t.routes||[]);var e=t.mode||"hash";this.fallback="history"===e&&!Et,this.fallback&&(e="hash"),Ot||(e="abstract"),this.mode=e},qt={currentRoute:{}};return qt.currentRoute.get=function(){return this.history&&this.history.current},Tt.prototype.init=function(t){var e=this;r(m.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before creating root instance."),this.app=t;var n=this,o=n.mode,i=n.options,a=n.fallback;switch(o){case"history":this.history=new $t(this,i.base);break;case"hash":this.history=new At(this,i.base,a);break;case"abstract":this.history=new _t(this);break;default:r(!1,"invalid mode: "+o)}this.history.listen(function(t){e.app._route=t})},Tt.prototype.beforeEach=function(t){this.beforeHooks.push(t)},Tt.prototype.afterEach=function(t){this.afterHooks.push(t)},Tt.prototype.push=function(t){this.history.push(t)},Tt.prototype.replace=function(t){this.history.replace(t)},Tt.prototype.go=function(t){this.history.go(t)},Tt.prototype.back=function(){this.go(-1)},Tt.prototype.forward=function(){this.go(1)},Tt.prototype.getMatchedComponents=function(){return this.currentRoute?[].concat.apply([],this.currentRoute.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Object.defineProperties(Tt.prototype,qt),Tt.install=m,Ot&&window.Vue&&window.Vue.use(Tt),Tt}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if("/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i<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){if(!t)throw new Error("[vue-router] "+e)}function o(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function i(t,e){if(void 0===e&&(e={}),t){var n;try{n=a(t)}catch(t){o(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function a(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=dt(n.shift()),o=n.length>0?dt(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return lt(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(lt(e)):r.push(lt(e)+"="+lt(t)))}),r.join("&")}return lt(e)+"="+lt(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function c(t,e,n){var r={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:f(e),matched:t?s(t):[]};return n&&(r.redirectedFrom=f(n)),Object.freeze(r)}function s(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function f(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+u(n)+r}function p(t,e){return e===yt?t===e:!!e&&(t.path&&e.path?t.path.replace(vt,"")===e.path.replace(vt,"")&&t.hash===e.hash&&h(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&h(t.query,e.query)&&h(t.params,e.params)))}function h(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function l(t,e){return 0===t.path.indexOf(e.path.replace(/\/$/,""))&&(!e.hash||t.hash===e.hash)&&d(t.query,e.query)}function d(t,e){for(var n in e)if(!(n in t))return!1;return!0}function y(n,r,o){var a="string"==typeof n?{path:n}:n;if(a.name||a._normalized)return a;var u=e(a.path||""),c=r&&r.path||"/",s=u.path?t(u.path,c,o):r&&r.path||"/",f=i(u.query,a.query),p=a.hash||u.hash;return p&&"#"!==p.charAt(0)&&(p="#"+p),{_normalized:!0,path:s,query:f,hash:p}}function v(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=v(e.children)))return e}}function m(t,e,r){var o="hash"===r?"/#"+e:e;return t?n(t+o):o}function g(t){if(!g.installed){g.installed=!0,pt=t,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",ht),t.component("router-link",gt);var e=t.config.optionMergeStrategies;e.beforeRouteEnter=e.beforeRouteLeave=e.created}}function w(t,e){for(var n,r=[],o=0,i=0,a="",u=e&&e.delimiter||"/";null!=(n=jt.exec(t));){var c=n[0],s=n[1],f=n.index;if(a+=t.slice(i,f),i=f+c.length,s)a+=s[1];else{var p=t[i],h=n[2],l=n[3],d=n[4],y=n[5],v=n[6],m=n[7];a&&(r.push(a),a="");var g=null!=h&&null!=p&&p!==h,w="+"===v||"*"===v,b="?"===v||"*"===v,x=n[2]||u,k=d||y;r.push({name:l||o++,prefix:h||"",delimiter:x,optional:b,repeat:w,partial:g,asterisk:!!m,pattern:k?R(k):m?".*":"[^"+E(x)+"]+?"})}}return i<t.length&&(a+=t.substr(i)),a&&r.push(a),r}function b(t,e){return O(w(t,e))}function x(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function k(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function O(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,r){for(var o="",i=n||{},a=r||{},u=a.pretty?x:encodeURIComponent,c=0;c<t.length;c++){var s=t[c];if("string"!=typeof s){var f,p=i[s.name];if(null==p){if(s.optional){s.partial&&(o+=s.prefix);continue}throw new TypeError('Expected "'+s.name+'" to be defined')}if(bt(p)){if(!s.repeat)throw new TypeError('Expected "'+s.name+'" to not repeat, but received `'+JSON.stringify(p)+"`");if(0===p.length){if(s.optional)continue;throw new TypeError('Expected "'+s.name+'" to not be empty')}for(var h=0;h<p.length;h++){if(f=u(p[h]),!e[c].test(f))throw new TypeError('Expected all "'+s.name+'" to match "'+s.pattern+'", but received `'+JSON.stringify(f)+"`");o+=(0===h?s.prefix:s.delimiter)+f}}else{if(f=s.asterisk?k(p):u(p),!e[c].test(f))throw new TypeError('Expected "'+s.name+'" to match "'+s.pattern+'", but received "'+f+'"');o+=s.prefix+f}}else o+=s}return o}}function E(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function R(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function j(t,e){return t.keys=e,t}function A(t){return t.sensitive?"":"i"}function $(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 j(t,e)}function _(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(q(t[o],e,n).source);var i=new RegExp("(?:"+r.join("|")+")",A(n));return j(i,e)}function S(t,e,n){return T(w(t,n),e,n)}function T(t,e,n){bt(e)||(n=e||n,e=[]),n=n||{};for(var r=n.strict,o=n.end!==!1,i="",a=0;a<t.length;a++){var u=t[a];if("string"==typeof u)i+=E(u);else{var c=E(u.prefix),s="(?:"+u.pattern+")";e.push(u),u.repeat&&(s+="(?:"+c+s+")*"),s=u.optional?u.partial?c+"("+s+")?":"(?:"+c+"("+s+"))?":c+"("+s+")",i+=s}}var f=E(n.delimiter||"/"),p=i.slice(-f.length)===f;return r||(i=(p?i.slice(0,-f.length):i)+"(?:"+f+"(?=$))?"),i+=o?"$":r&&p?"":"(?="+f+"|$)",j(new RegExp("^"+i,A(n)),e)}function q(t,e,n){return bt(e)||(n=e||n,e=[]),n=n||{},t instanceof RegExp?$(t,e):bt(t)?_(t,e,n):S(t,e,n)}function C(t){var e=Object.create(null),n=Object.create(null);return t.forEach(function(t){P(e,n,t)}),{pathMap:e,nameMap:n}}function P(t,e,n,i,a){var u=n.path,c=n.name;r(null!=u,'"path" is required in a route configuration.');var s={path:U(u,i),components:n.components||{default:n.component},instances:{},name:c,parent:i,matchAs:a,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{}};n.children&&n.children.forEach(function(n){P(t,e,n,s)}),void 0!==n.alias&&(Array.isArray(n.alias)?n.alias.forEach(function(n){P(t,e,{path:n},i,s.path)}):P(t,e,{path:n.alias},i,s.path)),t[s.path]=s,c&&(e[c]?o(!1,'Duplicate named routes definition: { name: "'+c+'", path: "'+s.path+'" }'):e[c]=s)}function U(t,e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:n(e.path+"/"+t)}function L(t){function e(t,e,n){var r=y(t,e),o=r.name;if(o){var i=f[o];if("object"!=typeof r.params&&(r.params={}),e&&"object"==typeof e.params)for(var u in e.params)u in r.params||(r.params[u]=e.params[u]);if(i)return r.path=M(i.path,r.params,'named route "'+o+'"'),a(i,r,n)}else if(r.path){r.params={};for(var c in s)if(V(c,r.params,r.path))return a(s[c],r,n)}return a(null,r)}function n(t,n){var i=t.redirect,u="function"==typeof i?i(c(t,n)):i;if("string"==typeof u&&(u={path:u}),!u||"object"!=typeof u)return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n);var s=u,p=s.name,h=s.path,l=n.query,d=n.hash,y=n.params;if(l=s.hasOwnProperty("query")?s.query:l,d=s.hasOwnProperty("hash")?s.hash:d,y=s.hasOwnProperty("params")?s.params:y,p){var v=f[p];return r(v,'redirect failed: named route "'+p+'" not found.'),e({_normalized:!0,name:p,query:l,hash:d,params:y},void 0,n)}if(h){var m=B(h,t),g=M(m,y,'redirect route with path "'+m+'"');return e({_normalized:!0,path:g,query:l,hash:d},void 0,n)}return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n)}function i(t,n,r){var o=M(r,n.params,'aliased route with path "'+r+'"'),i=e({_normalized:!0,path:o});if(i){var u=i.matched,c=u[u.length-1];return n.params=i.params,a(c,n)}return a(null,n)}function a(t,e,r){return t&&t.redirect?n(t,r||e):t&&t.matchAs?i(t,e,t.matchAs):c(t,e,r)}var u=C(t),s=u.pathMap,f=u.nameMap;return e}function V(t,e,n){var r,o,i=At[t];i?(r=i.keys,o=i.regexp):(r=[],o=xt(t,r),At[t]={keys:r,regexp:o});var a=n.match(o);if(!a)return!1;if(!e)return!0;for(var u=1,c=a.length;u<c;++u){var s=r[u-1],f="string"==typeof a[u]?decodeURIComponent(a[u]):a[u];s&&(e[s.name]=f)}return!0}function M(t,e,n){try{var o=$t[t]||($t[t]=xt.compile(t));return o(e||{},{pretty:!0})}catch(t){return r(!1,"missing param for "+n+": "+t.message),""}}function B(e,n){return t(e,n.parent?n.parent.path:"/",!0)}function H(t,e,n){var r=function(o){o>=t.length?n():t[o]?e(t[o],function(){r(o+1)}):r(o+1)};r(0)}function z(t){if(!t)if(_t){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function F(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 I(t,e){return"function"!=typeof t&&(t=pt.extend(t)),t.options[e]}function D(t){return G(W(t,function(t,e){var n=I(t,"beforeRouteLeave");if(n)return Array.isArray(n)?n.map(function(t){return J(t,e)}):J(n,e)}).reverse())}function J(t,e){return function(){return t.apply(e,arguments)}}function N(t,e,n){return G(W(t,function(t,r,o,i){var a=I(t,"beforeRouteEnter");if(a)return Array.isArray(a)?a.map(function(t){return K(t,e,o,i,n)}):K(a,e,o,i,n)}))}function K(t,e,n,r,o){return function(i,a,u){return t(i,a,function(t){u(t),"function"==typeof t&&e.push(function(){X(t,n.instances,r,o)})})}}function X(t,e,n,r){e[n]?t(e[n]):r()&&setTimeout(function(){X(t,e,n,r)},16)}function Y(t){return W(t,function(t,e,n,r){if("function"==typeof t&&!t.options)return function(e,i,a){var u=function(t){n.components[r]=t,a()},c=function(t){o(!1,"Failed to resolve async component "+r+": "+t),a(!1)},s=t(u,c);s&&"function"==typeof s.then&&s.then(u,c)}})}function W(t,e){return G(t.map(function(t){return Object.keys(t.components).map(function(n){return e(t.components[n],t.instances[n],t,n)})}))}function G(t){return Array.prototype.concat.apply([],t)}function Q(t){t&&(qt[t]={x:window.pageXOffset,y:window.pageYOffset})}function Z(t){if(t)return qt[t]}function tt(t){var e=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top}}function et(t){return rt(t.x)||rt(t.y)}function nt(t){return{x:rt(t.x)?t.x:window.pageXOffset,y:rt(t.y)?t.y:window.pageYOffset}}function rt(t){return"number"==typeof t}function ot(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 it(t,e){var n=window.history;try{e?n.replaceState({key:Pt},"",t):(Pt=Ct(),n.pushState({key:Pt},"",t)),Q(Pt)}catch(n){window.location[e?"assign":"replace"](t)}}function at(t){it(t,!0)}function ut(){var t=ct();return"/"===t.charAt(0)||(ft("/"+t),!1)}function ct(){var t=window.location.href,e=t.indexOf("#");return e===-1?"":t.slice(e+1)}function st(t){window.location.hash=t}function ft(t){var e=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,e>=0?e:0)+"#"+t)}var pt,ht={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,u=o._routerViewCache||(o._routerViewCache={}),c=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&c++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=c;var f=a.matched[c];if(!f)return t();var p=n.name,h=s?u[p]:u[p]=f.components[p];if(!s){var l=i.hook||(i.hook={});l.init=function(t){f.instances[p]=t.child},l.prepatch=function(t,e){f.instances[p]=e.child},l.destroy=function(t){f.instances[p]===t.child&&(f.instances[p]=void 0)}}return t(h,i,r)}},lt=encodeURIComponent,dt=decodeURIComponent,yt=c(null,{path:"/"}),vt=/\/$/,mt=[String,Object],gt={name:"router-link",props:{to:{type:mt,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,n=this.$router,r=this.$route,o=y(this.to,r,this.append),i=n.match(o,r),a=i.redirectedFrom||i.fullPath,u=n.history.base,s=m(u,a,n.mode),f={},h=this.activeClass||n.options.linkActiveClass||"router-link-active",d=o.path?c(null,o):i;f[h]=this.exact?p(r,d):l(r,d);var g={click:function(t){if(!(t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||0!==t.button)){var r=t.target.getAttribute("target");/\b_blank\b/i.test(r)||(t.preventDefault(),e.replace?n.replace(o):n.push(o))}}},w={class:f};if("a"===this.tag)w.on=g,w.attrs={href:s};else{var b=v(this.$slots.default);if(b){b.isStatic=!1;var x=pt.util.extend,k=b.data=x({},b.data);k.on=g;var O=b.data.attrs=x({},b.data.attrs);O.href=s}else w.on=g}return t(this.tag,w,this.$slots.default)}},wt=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},bt=wt,xt=q,kt=w,Ot=b,Et=O,Rt=T,jt=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");xt.parse=kt,xt.compile=Ot,xt.tokensToFunction=Et,xt.tokensToRegExp=Rt;var At=Object.create(null),$t=Object.create(null),_t="undefined"!=typeof window,St=_t&&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)}(),Tt=function(t,e){this.router=t,this.base=z(e),this.current=yt,this.pending=null};Tt.prototype.listen=function(t){this.cb=t},Tt.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r),n.ensureURL()})},Tt.prototype.confirmTransition=function(t,e){var n=this,r=this.current;if(p(t,r))return void this.ensureURL();var o=F(this.current.matched,t.matched),i=o.deactivated,a=o.activated,u=[].concat(D(i),this.router.beforeHooks,a.map(function(t){return t.beforeEnter}),Y(a));this.pending=t;var c=function(e,o){n.pending===t&&e(t,r,function(t){t===!1?n.ensureURL(!0):"string"==typeof t||"object"==typeof t?n.push(t):o(t)})};H(u,c,function(){var r=[],o=N(a,r,function(){return n.current===t});H(o,c,function(){n.pending===t&&(n.pending=null,e(t),n.router.app.$nextTick(function(){r.forEach(function(t){return t()})}))})})},Tt.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(n){n&&n(t,e)})};var qt=Object.create(null),Ct=function(){return String(Date.now())},Pt=Ct(),Ut=function(t){function e(e,n){var r=this;t.call(this,e,n);var o=e.options.scrollBehavior;window.addEventListener("popstate",function(t){Pt=t.state&&t.state.key;var e=r.current;r.transitionTo(ot(r.base),function(t){o&&r.handleScroll(t,e,!0)})}),o&&window.addEventListener("scroll",function(){Q(Pt)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){it(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.replace=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){at(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.ensureURL=function(t){if(ot(this.base)!==this.current.fullPath){var e=n(this.base+this.current.fullPath);t?it(e):at(e)}},e.prototype.handleScroll=function(t,e,n){var o=this.router;if(o.app){var i=o.options.scrollBehavior;i&&(r("function"==typeof i,"scrollBehavior must be a function"),o.app.$nextTick(function(){var r=Z(Pt),o=i(t,e,n?r:null);if(o){var a="object"==typeof o;if(a&&"string"==typeof o.selector){var u=document.querySelector(o.selector);u?r=tt(u):et(o)&&(r=nt(o))}else a&&et(o)&&(r=nt(o));r&&window.scrollTo(r.x,r.y)}}))}},e}(Tt),Lt=function(t){function e(e,n,r){t.call(this,e,n),r&&this.checkFallback()||ut()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkFallback=function(){var t=ot(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.onHashChange=function(){ut()&&this.transitionTo(ct(),function(t){ft(t.fullPath)})},e.prototype.push=function(t){this.transitionTo(t,function(t){st(t.fullPath)})},e.prototype.replace=function(t){this.transitionTo(t,function(t){ft(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;ct()!==e&&(t?st(e):ft(e))},e}(Tt),Vt=function(t){function e(e){t.call(this,e),this.stack=[],this.index=-1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(t){var e=this;this.transitionTo(t,function(t){e.stack=e.stack.slice(0,e.index+1).concat(t),e.index++})},e.prototype.replace=function(t){var e=this;this.transitionTo(t,function(t){e.stack=e.stack.slice(0,e.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e.prototype.ensureURL=function(){},e}(Tt),Mt=function(t){void 0===t&&(t={}),this.app=null,this.options=t,this.beforeHooks=[],this.afterHooks=[],this.match=L(t.routes||[]);var e=t.mode||"hash";switch(this.fallback="history"===e&&!St,this.fallback&&(e="hash"),_t||(e="abstract"),this.mode=e,e){case"history":this.history=new Ut(this,t.base);break;case"hash":this.history=new Lt(this,t.base,this.fallback);break;case"abstract":this.history=new Vt(this);break;default:r(!1,"invalid mode: "+e)}},Bt={currentRoute:{}};return Bt.currentRoute.get=function(){return this.history&&this.history.current},Mt.prototype.init=function(t){var e=this;r(g.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before creating root instance."),this.app=t;var n=this.history;n instanceof Ut?n.transitionTo(ot(n.base)):n instanceof Lt&&n.transitionTo(ct(),function(){window.addEventListener("hashchange",function(){n.onHashChange()})}),n.listen(function(t){e.app._route=t})},Mt.prototype.beforeEach=function(t){this.beforeHooks.push(t)},Mt.prototype.afterEach=function(t){this.afterHooks.push(t)},Mt.prototype.push=function(t){this.history.push(t)},Mt.prototype.replace=function(t){this.history.replace(t)},Mt.prototype.go=function(t){this.history.go(t)},Mt.prototype.back=function(){this.go(-1)},Mt.prototype.forward=function(){this.go(1)},Mt.prototype.getMatchedComponents=function(){return this.currentRoute?[].concat.apply([],this.currentRoute.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Object.defineProperties(Mt.prototype,Bt),Mt.install=g,_t&&window.Vue&&window.Vue.use(Mt),Mt}); |
{ | ||
"name": "vue-router", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Official router for Vue.js 2.0", | ||
@@ -52,3 +52,3 @@ "author": "Evan You", | ||
"express-urlrewrite": "^1.2.0", | ||
"flow-bin": "^0.32.0", | ||
"flow-bin": "^0.33.0", | ||
"gitbook-plugin-edit-link": "^2.0.2", | ||
@@ -55,0 +55,0 @@ "gitbook-plugin-github": "^2.0.0", |
@@ -49,3 +49,3 @@ # vue-router [![Build Status](https://img.shields.io/circleci/project/vuejs/vue-router/dev.svg)](https://circleci.com/gh/vuejs/vue-router) | ||
Please make sure to read the [Contributing Guide](https://github.com/vuejs/vue/blob/dev/CONTRIBUTING.md) before making a pull request. | ||
Please make sure to read the [Contributing Guide](https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md) before making a pull request. | ||
@@ -52,0 +52,0 @@ ## Changelog |
@@ -6,2 +6,3 @@ /* @flow */ | ||
import { normalizeLocation } from '../util/location' | ||
import { _Vue } from '../install' | ||
@@ -31,6 +32,6 @@ // work around weird flow bug | ||
const to = normalizeLocation(this.to, current, this.append) | ||
const resolved = router.match(to) | ||
const resolved = router.match(to, current) | ||
const fullPath = resolved.redirectedFrom || resolved.fullPath | ||
const base = router.history.base | ||
const href = base ? cleanPath(base + fullPath) : fullPath | ||
const href = createHref(base, fullPath, router.mode) | ||
const classes = {} | ||
@@ -54,2 +55,7 @@ const activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active' | ||
if (e.button !== 0) return | ||
// don't redirect if `target="_blank"` | ||
/* istanbul ignore if */ | ||
const target = e.target.getAttribute('target') | ||
if (/\b_blank\b/i.test(target)) return | ||
e.preventDefault() | ||
@@ -75,5 +81,8 @@ if (this.replace) { | ||
if (a) { | ||
const aData = a.data || (a.data = {}) | ||
// in case the <a> is a static node | ||
a.isStatic = false | ||
const extend = _Vue.util.extend | ||
const aData = a.data = extend({}, a.data) | ||
aData.on = on | ||
const aAttrs = aData.attrs || (aData.attrs = {}) | ||
const aAttrs = a.data.attrs = extend({}, a.data.attrs) | ||
aAttrs.href = href | ||
@@ -104,1 +113,6 @@ } else { | ||
} | ||
function createHref (base, fullPath, mode) { | ||
var path = mode === 'hash' ? '/#' + fullPath : fullPath | ||
return base ? cleanPath(base + path) : path | ||
} |
@@ -44,2 +44,5 @@ export default { | ||
} | ||
hooks.prepatch = (oldVnode, vnode) => { | ||
matched.instances[name] = vnode.child | ||
} | ||
hooks.destroy = vnode => { | ||
@@ -46,0 +49,0 @@ if (matched.instances[name] === vnode.child) { |
@@ -34,2 +34,15 @@ /* @flow */ | ||
const record = nameMap[name] | ||
if (typeof location.params !== 'object') { | ||
location.params = {} | ||
} | ||
if (currentRoute && typeof currentRoute.params === 'object') { | ||
for (const key in currentRoute.params) { | ||
if (!(key in location.params)) { | ||
location.params[key] = currentRoute.params[key] | ||
} | ||
} | ||
} | ||
if (record) { | ||
@@ -36,0 +49,0 @@ location.path = fillParams(record.path, location.params, `named route "${name}"`) |
@@ -62,3 +62,3 @@ /* @flow */ | ||
if (route.alias) { | ||
if (route.alias !== undefined) { | ||
if (Array.isArray(route.alias)) { | ||
@@ -74,3 +74,9 @@ route.alias.forEach(alias => { | ||
pathMap[record.path] = record | ||
if (name) nameMap[name] = record | ||
if (name) { | ||
if (!nameMap[name]) { | ||
nameMap[name] = record | ||
} else { | ||
warn(false, `Duplicate named routes definition: { name: "${name}", path: "${record.path}" }`) | ||
} | ||
} | ||
} | ||
@@ -77,0 +83,0 @@ |
@@ -8,2 +8,3 @@ /* @flow */ | ||
import { START, isSameRoute } from '../util/route' | ||
import { _Vue } from '../install' | ||
@@ -21,3 +22,3 @@ export class History { | ||
replace: (loc: RawLocation) => void; | ||
ensureURL: () => void; | ||
ensureURL: (push?: boolean) => void; | ||
@@ -74,3 +75,3 @@ constructor (router: VueRouter, base: ?string) { | ||
// next(false) -> abort navigation, ensure current URL | ||
this.ensureURL() | ||
this.ensureURL(true) | ||
} else if (typeof to === 'string' || typeof to === 'object') { | ||
@@ -153,13 +154,33 @@ // next('/') or next({ path: '/' }) -> redirect | ||
function extractGuard ( | ||
def: Object | Function, | ||
key: string | ||
): NavigationGuard | Array<NavigationGuard> { | ||
if (typeof def !== 'function') { | ||
// extend now so that global mixins are applied. | ||
def = _Vue.extend(def) | ||
} | ||
return def.options[key] | ||
} | ||
function extractLeaveGuards (matched: Array<RouteRecord>): Array<?Function> { | ||
return flatMapComponents(matched, (def, instance) => { | ||
const guard = def && def.beforeRouteLeave | ||
return flatten(flatMapComponents(matched, (def, instance) => { | ||
const guard = extractGuard(def, 'beforeRouteLeave') | ||
if (guard) { | ||
return function routeLeaveGuard () { | ||
return guard.apply(instance, arguments) | ||
} | ||
return Array.isArray(guard) | ||
? guard.map(guard => wrapLeaveGuard(guard, instance)) | ||
: wrapLeaveGuard(guard, instance) | ||
} | ||
}).reverse() | ||
}).reverse()) | ||
} | ||
function wrapLeaveGuard ( | ||
guard: NavigationGuard, | ||
instance: _Vue | ||
): NavigationGuard { | ||
return function routeLeaveGuard () { | ||
return guard.apply(instance, arguments) | ||
} | ||
} | ||
function extractEnterGuards ( | ||
@@ -170,25 +191,42 @@ matched: Array<RouteRecord>, | ||
): Array<?Function> { | ||
return flatMapComponents(matched, (def, _, match, key) => { | ||
const guard = def && def.beforeRouteEnter | ||
return flatten(flatMapComponents(matched, (def, _, match, key) => { | ||
const guard = extractGuard(def, 'beforeRouteEnter') | ||
if (guard) { | ||
return function routeEnterGuard (to, from, next) { | ||
return guard(to, from, cb => { | ||
next(cb) | ||
if (typeof cb === 'function') { | ||
cbs.push(() => { | ||
// #750 | ||
// if a router-view is wrapped with an out-in transition, | ||
// the instance may not have been registered at this time. | ||
// we will need to poll for registration until current route | ||
// is no longer valid. | ||
poll(cb, match.instances, key, isValid) | ||
}) | ||
} | ||
return Array.isArray(guard) | ||
? guard.map(guard => wrapEnterGuard(guard, cbs, match, key, isValid)) | ||
: wrapEnterGuard(guard, cbs, match, key, isValid) | ||
} | ||
})) | ||
} | ||
function wrapEnterGuard ( | ||
guard: NavigationGuard, | ||
cbs: Array<Function>, | ||
match: RouteRecord, | ||
key: string, | ||
isValid: () => boolean | ||
): NavigationGuard { | ||
return function routeEnterGuard (to, from, next) { | ||
return guard(to, from, cb => { | ||
next(cb) | ||
if (typeof cb === 'function') { | ||
cbs.push(() => { | ||
// #750 | ||
// if a router-view is wrapped with an out-in transition, | ||
// the instance may not have been registered at this time. | ||
// we will need to poll for registration until current route | ||
// is no longer valid. | ||
poll(cb, match.instances, key, isValid) | ||
}) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
function poll (cb, instances, key, isValid) { | ||
function poll ( | ||
cb: any, // somehow flow cannot infer this is a function | ||
instances: Object, | ||
key: string, | ||
isValid: () => boolean | ||
) { | ||
if (instances[key]) { | ||
@@ -235,3 +273,3 @@ cb(instances[key]) | ||
): Array<?Function> { | ||
return Array.prototype.concat.apply([], matched.map(m => { | ||
return flatten(matched.map(m => { | ||
return Object.keys(m.components).map(key => fn( | ||
@@ -244,1 +282,5 @@ m.components[key], | ||
} | ||
function flatten (arr) { | ||
return Array.prototype.concat.apply([], arr) | ||
} |
@@ -18,7 +18,2 @@ /* @flow */ | ||
ensureSlash() | ||
this.transitionTo(getHash(), () => { | ||
window.addEventListener('hashchange', () => { | ||
this.onHashChange() | ||
}) | ||
}) | ||
} | ||
@@ -61,5 +56,6 @@ | ||
ensureURL () { | ||
if (getHash() !== this.current.fullPath) { | ||
replaceHash(this.current.fullPath) | ||
ensureURL (push?: boolean) { | ||
const current = this.current.fullPath | ||
if (getHash() !== current) { | ||
push ? pushHash(current) : replaceHash(current) | ||
} | ||
@@ -78,3 +74,3 @@ } | ||
function getHash (): string { | ||
export function getHash (): string { | ||
// We can't use window.location.hash here because it's not | ||
@@ -81,0 +77,0 @@ // consistent across browsers - Firefox will pre-decode it! |
@@ -22,4 +22,2 @@ /* @flow */ | ||
this.transitionTo(getLocation(this.base)) | ||
const expectScroll = router.options.scrollBehavior | ||
@@ -63,5 +61,6 @@ window.addEventListener('popstate', e => { | ||
ensureURL () { | ||
ensureURL (push?: boolean) { | ||
if (getLocation(this.base) !== this.current.fullPath) { | ||
replaceState(cleanPath(this.base + this.current.fullPath)) | ||
const current = cleanPath(this.base + this.current.fullPath) | ||
push ? pushState(current) : replaceState(current) | ||
} | ||
@@ -68,0 +67,0 @@ } |
@@ -5,4 +5,4 @@ /* @flow */ | ||
import { createMatcher } from './create-matcher' | ||
import { HashHistory } from './history/hash' | ||
import { HTML5History } from './history/html5' | ||
import { HashHistory, getHash } from './history/hash' | ||
import { HTML5History, getLocation } from './history/html5' | ||
import { AbstractHistory } from './history/abstract' | ||
@@ -40,2 +40,16 @@ import { inBrowser, supportsHistory } from './util/dom' | ||
this.mode = mode | ||
switch (mode) { | ||
case 'history': | ||
this.history = new HTML5History(this, options.base) | ||
break | ||
case 'hash': | ||
this.history = new HashHistory(this, options.base, this.fallback) | ||
break | ||
case 'abstract': | ||
this.history = new AbstractHistory(this) | ||
break | ||
default: | ||
assert(false, `invalid mode: ${mode}`) | ||
} | ||
} | ||
@@ -56,18 +70,15 @@ | ||
const { mode, options, fallback } = this | ||
switch (mode) { | ||
case 'history': | ||
this.history = new HTML5History(this, options.base) | ||
break | ||
case 'hash': | ||
this.history = new HashHistory(this, options.base, fallback) | ||
break | ||
case 'abstract': | ||
this.history = new AbstractHistory(this) | ||
break | ||
default: | ||
assert(false, `invalid mode: ${mode}`) | ||
const history = this.history | ||
if (history instanceof HTML5History) { | ||
history.transitionTo(getLocation(history.base)) | ||
} else if (history instanceof HashHistory) { | ||
history.transitionTo(getHash(), () => { | ||
window.addEventListener('hashchange', () => { | ||
history.onHashChange() | ||
}) | ||
}) | ||
} | ||
this.history.listen(route => { | ||
history.listen(route => { | ||
this.app._route = route | ||
@@ -74,0 +85,0 @@ }) |
import View from './components/view' | ||
import Link from './components/link' | ||
export let _Vue | ||
export function install (Vue) { | ||
@@ -8,2 +10,4 @@ if (install.installed) return | ||
_Vue = Vue | ||
Object.defineProperty(Vue.prototype, '$router', { | ||
@@ -29,2 +33,6 @@ get () { return this.$root._router } | ||
Vue.component('router-link', Link) | ||
const strats = Vue.config.optionMergeStrategies | ||
// use the same hook merging strategy for route hooks | ||
strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created | ||
} |
@@ -30,3 +30,3 @@ /* @flow */ | ||
function parseQuery (query: string): Dictionary<string> { | ||
const res = Object.create(null) | ||
const res = {} | ||
@@ -33,0 +33,0 @@ query = query.trim().replace(/^(\?|#|&)/, '') |
@@ -79,3 +79,3 @@ /* @flow */ | ||
return ( | ||
current.path.indexOf(target.path) === 0 && | ||
current.path.indexOf(target.path.replace(/\/$/, '')) === 0 && | ||
(!target.hash || current.hash === target.hash) && | ||
@@ -82,0 +82,0 @@ queryIncludes(current.query, target.query) |
/* @flow */ | ||
const positionStore = Object.create(null) | ||
export function saveScrollPosition (key: string) { | ||
if (!key) return | ||
window.sessionStorage.setItem(key, JSON.stringify({ | ||
positionStore[key] = { | ||
x: window.pageXOffset, | ||
y: window.pageYOffset | ||
})) | ||
} | ||
} | ||
@@ -13,3 +15,3 @@ | ||
if (!key) return | ||
return JSON.parse(window.sessionStorage.getItem(key)) | ||
return positionStore[key] | ||
} | ||
@@ -16,0 +18,0 @@ |
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
114555
26
3147