|
|
@ -1,5 +1,5 @@ |
|
|
|
/*! |
|
|
|
* vue-router v3.1.6 |
|
|
|
* vue-router v3.4.3 |
|
|
|
* (c) 2020 Evan You |
|
|
|
* @license MIT |
|
|
|
*/ |
|
|
@ -23,18 +23,6 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function isError (err) { |
|
|
|
return Object.prototype.toString.call(err).indexOf('Error') > -1 |
|
|
|
} |
|
|
|
|
|
|
|
function isExtendedError (constructor, err) { |
|
|
|
return ( |
|
|
|
err instanceof constructor || |
|
|
|
// _name is to support IE9 too
|
|
|
|
(err && (err.name === constructor.name || err._name === constructor._name)) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
function extend (a, b) { |
|
|
|
for (var key in b) { |
|
|
|
a[key] = b[key]; |
|
|
@ -143,7 +131,7 @@ |
|
|
|
}; |
|
|
|
|
|
|
|
var configProps = matched.props && matched.props[name]; |
|
|
|
// save route and configProps in cachce
|
|
|
|
// save route and configProps in cache
|
|
|
|
if (configProps) { |
|
|
|
extend(cache[name], { |
|
|
|
route: route, |
|
|
@ -204,8 +192,8 @@ |
|
|
|
// - escapes [!'()*]
|
|
|
|
// - preserve commas
|
|
|
|
var encode = function (str) { return encodeURIComponent(str) |
|
|
|
.replace(encodeReserveRE, encodeReserveReplacer) |
|
|
|
.replace(commaRE, ','); }; |
|
|
|
.replace(encodeReserveRE, encodeReserveReplacer) |
|
|
|
.replace(commaRE, ','); }; |
|
|
|
|
|
|
|
var decode = decodeURIComponent; |
|
|
|
|
|
|
@ -225,11 +213,16 @@ |
|
|
|
parsedQuery = {}; |
|
|
|
} |
|
|
|
for (var key in extraQuery) { |
|
|
|
parsedQuery[key] = extraQuery[key]; |
|
|
|
var value = extraQuery[key]; |
|
|
|
parsedQuery[key] = Array.isArray(value) |
|
|
|
? value.map(castQueryParamValue) |
|
|
|
: castQueryParamValue(value); |
|
|
|
} |
|
|
|
return parsedQuery |
|
|
|
} |
|
|
|
|
|
|
|
var castQueryParamValue = function (value) { return (value == null || typeof value === 'object' ? value : String(value)); }; |
|
|
|
|
|
|
|
function parseQuery (query) { |
|
|
|
var res = {}; |
|
|
|
|
|
|
@ -242,9 +235,7 @@ |
|
|
|
query.split('&').forEach(function (param) { |
|
|
|
var parts = param.replace(/\+/g, ' ').split('='); |
|
|
|
var key = decode(parts.shift()); |
|
|
|
var val = parts.length > 0 |
|
|
|
? decode(parts.join('=')) |
|
|
|
: null; |
|
|
|
var val = parts.length > 0 ? decode(parts.join('=')) : null; |
|
|
|
|
|
|
|
if (res[key] === undefined) { |
|
|
|
res[key] = val; |
|
|
@ -259,34 +250,39 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function stringifyQuery (obj) { |
|
|
|
var res = obj ? Object.keys(obj).map(function (key) { |
|
|
|
var val = obj[key]; |
|
|
|
var res = obj |
|
|
|
? Object.keys(obj) |
|
|
|
.map(function (key) { |
|
|
|
var val = obj[key]; |
|
|
|
|
|
|
|
if (val === undefined) { |
|
|
|
return '' |
|
|
|
} |
|
|
|
|
|
|
|
if (val === null) { |
|
|
|
return encode(key) |
|
|
|
} |
|
|
|
if (val === undefined) { |
|
|
|
return '' |
|
|
|
} |
|
|
|
|
|
|
|
if (Array.isArray(val)) { |
|
|
|
var result = []; |
|
|
|
val.forEach(function (val2) { |
|
|
|
if (val2 === undefined) { |
|
|
|
return |
|
|
|
if (val === null) { |
|
|
|
return encode(key) |
|
|
|
} |
|
|
|
if (val2 === null) { |
|
|
|
result.push(encode(key)); |
|
|
|
} else { |
|
|
|
result.push(encode(key) + '=' + encode(val2)); |
|
|
|
|
|
|
|
if (Array.isArray(val)) { |
|
|
|
var result = []; |
|
|
|
val.forEach(function (val2) { |
|
|
|
if (val2 === undefined) { |
|
|
|
return |
|
|
|
} |
|
|
|
if (val2 === null) { |
|
|
|
result.push(encode(key)); |
|
|
|
} else { |
|
|
|
result.push(encode(key) + '=' + encode(val2)); |
|
|
|
} |
|
|
|
}); |
|
|
|
return result.join('&') |
|
|
|
} |
|
|
|
}); |
|
|
|
return result.join('&') |
|
|
|
} |
|
|
|
|
|
|
|
return encode(key) + '=' + encode(val) |
|
|
|
}).filter(function (x) { return x.length > 0; }).join('&') : null; |
|
|
|
return encode(key) + '=' + encode(val) |
|
|
|
}) |
|
|
|
.filter(function (x) { return x.length > 0; }) |
|
|
|
.join('&') |
|
|
|
: null; |
|
|
|
return res ? ("?" + res) : '' |
|
|
|
} |
|
|
|
|
|
|
@ -400,6 +396,8 @@ |
|
|
|
return aKeys.every(function (key) { |
|
|
|
var aVal = a[key]; |
|
|
|
var bVal = b[key]; |
|
|
|
// query values can be null and undefined
|
|
|
|
if (aVal == null || bVal == null) { return aVal === bVal } |
|
|
|
// check nested equality
|
|
|
|
if (typeof aVal === 'object' && typeof bVal === 'object') { |
|
|
|
return isObjectEqual(aVal, bVal) |
|
|
@ -610,7 +608,7 @@ |
|
|
|
* @return {!function(Object=, Object=)} |
|
|
|
*/ |
|
|
|
function compile (str, options) { |
|
|
|
return tokensToFunction(parse(str, options)) |
|
|
|
return tokensToFunction(parse(str, options), options) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -640,14 +638,14 @@ |
|
|
|
/** |
|
|
|
* Expose a method for transforming tokens into the path function. |
|
|
|
*/ |
|
|
|
function tokensToFunction (tokens) { |
|
|
|
function tokensToFunction (tokens, options) { |
|
|
|
// Compile all the tokens into regexps.
|
|
|
|
var matches = new Array(tokens.length); |
|
|
|
|
|
|
|
// Compile all the patterns before compilation.
|
|
|
|
for (var i = 0; i < tokens.length; i++) { |
|
|
|
if (typeof tokens[i] === 'object') { |
|
|
|
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$'); |
|
|
|
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -760,7 +758,7 @@ |
|
|
|
* @return {string} |
|
|
|
*/ |
|
|
|
function flags (options) { |
|
|
|
return options.sensitive ? '' : 'i' |
|
|
|
return options && options.sensitive ? '' : 'i' |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -1051,6 +1049,10 @@ |
|
|
|
replace: Boolean, |
|
|
|
activeClass: String, |
|
|
|
exactActiveClass: String, |
|
|
|
ariaCurrentValue: { |
|
|
|
type: String, |
|
|
|
default: 'page' |
|
|
|
}, |
|
|
|
event: { |
|
|
|
type: eventTypes, |
|
|
|
default: 'click' |
|
|
@ -1096,6 +1098,8 @@ |
|
|
|
? classes[exactActiveClass] |
|
|
|
: isIncludedRoute(current, compareTarget); |
|
|
|
|
|
|
|
var ariaCurrentValue = classes[exactActiveClass] ? this.ariaCurrentValue : null; |
|
|
|
|
|
|
|
var handler = function (e) { |
|
|
|
if (guardEvent(e)) { |
|
|
|
if (this$1.replace) { |
|
|
@ -1144,7 +1148,7 @@ |
|
|
|
|
|
|
|
if (this.tag === 'a') { |
|
|
|
data.on = on; |
|
|
|
data.attrs = { href: href }; |
|
|
|
data.attrs = { href: href, 'aria-current': ariaCurrentValue }; |
|
|
|
} else { |
|
|
|
// find the first <a> child and apply listener and href
|
|
|
|
var a = findAnchor(this.$slots.default); |
|
|
@ -1172,6 +1176,7 @@ |
|
|
|
|
|
|
|
var aAttrs = (a.data.attrs = extend({}, a.data.attrs)); |
|
|
|
aAttrs.href = href; |
|
|
|
aAttrs['aria-current'] = ariaCurrentValue; |
|
|
|
} else { |
|
|
|
// doesn't have <a> child, apply listener to self
|
|
|
|
data.on = on; |
|
|
@ -1690,6 +1695,10 @@ |
|
|
|
var positionStore = Object.create(null); |
|
|
|
|
|
|
|
function setupScroll () { |
|
|
|
// Prevent browser scroll behavior on History popstate
|
|
|
|
if ('scrollRestoration' in window.history) { |
|
|
|
window.history.scrollRestoration = 'manual'; |
|
|
|
} |
|
|
|
// Fix for #1585 for Firefox
|
|
|
|
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
|
|
|
|
// Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
|
|
|
@ -1701,12 +1710,10 @@ |
|
|
|
var stateCopy = extend({}, window.history.state); |
|
|
|
stateCopy.key = getStateKey(); |
|
|
|
window.history.replaceState(stateCopy, '', absolutePath); |
|
|
|
window.addEventListener('popstate', function (e) { |
|
|
|
saveScrollPosition(); |
|
|
|
if (e.state && e.state.key) { |
|
|
|
setStateKey(e.state.key); |
|
|
|
} |
|
|
|
}); |
|
|
|
window.addEventListener('popstate', handlePopState); |
|
|
|
return function () { |
|
|
|
window.removeEventListener('popstate', handlePopState); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function handleScroll ( |
|
|
@ -1768,6 +1775,13 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function handlePopState (e) { |
|
|
|
saveScrollPosition(); |
|
|
|
if (e.state && e.state.key) { |
|
|
|
setStateKey(e.state.key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function getScrollPosition () { |
|
|
|
var key = getStateKey(); |
|
|
|
if (key) { |
|
|
@ -1853,7 +1867,7 @@ |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
return window.history && 'pushState' in window.history |
|
|
|
return window.history && typeof window.history.pushState === 'function' |
|
|
|
})(); |
|
|
|
|
|
|
|
function pushState (url, replace) { |
|
|
@ -1898,6 +1912,88 @@ |
|
|
|
step(0); |
|
|
|
} |
|
|
|
|
|
|
|
var NavigationFailureType = { |
|
|
|
redirected: 2, |
|
|
|
aborted: 4, |
|
|
|
cancelled: 8, |
|
|
|
duplicated: 16 |
|
|
|
}; |
|
|
|
|
|
|
|
function createNavigationRedirectedError (from, to) { |
|
|
|
return createRouterError( |
|
|
|
from, |
|
|
|
to, |
|
|
|
NavigationFailureType.redirected, |
|
|
|
("Redirected when going from \"" + (from.fullPath) + "\" to \"" + (stringifyRoute( |
|
|
|
to |
|
|
|
)) + "\" via a navigation guard.") |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
function createNavigationDuplicatedError (from, to) { |
|
|
|
var error = createRouterError( |
|
|
|
from, |
|
|
|
to, |
|
|
|
NavigationFailureType.duplicated, |
|
|
|
("Avoided redundant navigation to current location: \"" + (from.fullPath) + "\".") |
|
|
|
); |
|
|
|
// backwards compatible with the first introduction of Errors
|
|
|
|
error.name = 'NavigationDuplicated'; |
|
|
|
return error |
|
|
|
} |
|
|
|
|
|
|
|
function createNavigationCancelledError (from, to) { |
|
|
|
return createRouterError( |
|
|
|
from, |
|
|
|
to, |
|
|
|
NavigationFailureType.cancelled, |
|
|
|
("Navigation cancelled from \"" + (from.fullPath) + "\" to \"" + (to.fullPath) + "\" with a new navigation.") |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
function createNavigationAbortedError (from, to) { |
|
|
|
return createRouterError( |
|
|
|
from, |
|
|
|
to, |
|
|
|
NavigationFailureType.aborted, |
|
|
|
("Navigation aborted from \"" + (from.fullPath) + "\" to \"" + (to.fullPath) + "\" via a navigation guard.") |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
function createRouterError (from, to, type, message) { |
|
|
|
var error = new Error(message); |
|
|
|
error._isRouter = true; |
|
|
|
error.from = from; |
|
|
|
error.to = to; |
|
|
|
error.type = type; |
|
|
|
|
|
|
|
return error |
|
|
|
} |
|
|
|
|
|
|
|
var propertiesToLog = ['params', 'query', 'hash']; |
|
|
|
|
|
|
|
function stringifyRoute (to) { |
|
|
|
if (typeof to === 'string') { return to } |
|
|
|
if ('path' in to) { return to.path } |
|
|
|
var location = {}; |
|
|
|
propertiesToLog.forEach(function (key) { |
|
|
|
if (key in to) { location[key] = to[key]; } |
|
|
|
}); |
|
|
|
return JSON.stringify(location, null, 2) |
|
|
|
} |
|
|
|
|
|
|
|
function isError (err) { |
|
|
|
return Object.prototype.toString.call(err).indexOf('Error') > -1 |
|
|
|
} |
|
|
|
|
|
|
|
function isNavigationFailure (err, errorType) { |
|
|
|
return ( |
|
|
|
isError(err) && |
|
|
|
err._isRouter && |
|
|
|
(errorType == null || err.type === errorType) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
/* */ |
|
|
|
|
|
|
|
function resolveAsyncComponents (matched) { |
|
|
@ -2007,33 +2103,6 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var NavigationDuplicated = /*@__PURE__*/(function (Error) { |
|
|
|
function NavigationDuplicated (normalizedLocation) { |
|
|
|
Error.call(this); |
|
|
|
this.name = this._name = 'NavigationDuplicated'; |
|
|
|
// passing the message to super() doesn't seem to work in the transpiled version
|
|
|
|
this.message = "Navigating to current location (\"" + (normalizedLocation.fullPath) + "\") is not allowed"; |
|
|
|
// add a stack property so services like Sentry can correctly display it
|
|
|
|
Object.defineProperty(this, 'stack', { |
|
|
|
value: new Error().stack, |
|
|
|
writable: true, |
|
|
|
configurable: true |
|
|
|
}); |
|
|
|
// we could also have used
|
|
|
|
// Error.captureStackTrace(this, this.constructor)
|
|
|
|
// but it only exists on node and chrome
|
|
|
|
} |
|
|
|
|
|
|
|
if ( Error ) NavigationDuplicated.__proto__ = Error; |
|
|
|
NavigationDuplicated.prototype = Object.create( Error && Error.prototype ); |
|
|
|
NavigationDuplicated.prototype.constructor = NavigationDuplicated; |
|
|
|
|
|
|
|
return NavigationDuplicated; |
|
|
|
}(Error)); |
|
|
|
|
|
|
|
// support IE9
|
|
|
|
NavigationDuplicated._name = 'NavigationDuplicated'; |
|
|
|
|
|
|
|
/* */ |
|
|
|
|
|
|
|
var History = function History (router, base) { |
|
|
@ -2046,6 +2115,7 @@ |
|
|
|
this.readyCbs = []; |
|
|
|
this.readyErrorCbs = []; |
|
|
|
this.errorCbs = []; |
|
|
|
this.listeners = []; |
|
|
|
}; |
|
|
|
|
|
|
|
History.prototype.listen = function listen (cb) { |
|
|
@ -2074,13 +2144,27 @@ |
|
|
|
) { |
|
|
|
var this$1 = this; |
|
|
|
|
|
|
|
var route = this.router.match(location, this.current); |
|
|
|
var route; |
|
|
|
// catch redirect option https://github.com/vuejs/vue-router/issues/3201
|
|
|
|
try { |
|
|
|
route = this.router.match(location, this.current); |
|
|
|
} catch (e) { |
|
|
|
this.errorCbs.forEach(function (cb) { |
|
|
|
cb(e); |
|
|
|
}); |
|
|
|
// Exception should still be thrown
|
|
|
|
throw e |
|
|
|
} |
|
|
|
this.confirmTransition( |
|
|
|
route, |
|
|
|
function () { |
|
|
|
var prev = this$1.current; |
|
|
|
this$1.updateRoute(route); |
|
|
|
onComplete && onComplete(route); |
|
|
|
this$1.ensureURL(); |
|
|
|
this$1.router.afterHooks.forEach(function (hook) { |
|
|
|
hook && hook(route, prev); |
|
|
|
}); |
|
|
|
|
|
|
|
// fire ready cbs once
|
|
|
|
if (!this$1.ready) { |
|
|
@ -2096,9 +2180,17 @@ |
|
|
|
} |
|
|
|
if (err && !this$1.ready) { |
|
|
|
this$1.ready = true; |
|
|
|
this$1.readyErrorCbs.forEach(function (cb) { |
|
|
|
cb(err); |
|
|
|
}); |
|
|
|
// Initial redirection should still trigger the onReady onSuccess
|
|
|
|
// https://github.com/vuejs/vue-router/issues/3225
|
|
|
|
if (!isNavigationFailure(err, NavigationFailureType.redirected)) { |
|
|
|
this$1.readyErrorCbs.forEach(function (cb) { |
|
|
|
cb(err); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this$1.readyCbs.forEach(function (cb) { |
|
|
|
cb(route); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
@ -2109,11 +2201,10 @@ |
|
|
|
|
|
|
|
var current = this.current; |
|
|
|
var abort = function (err) { |
|
|
|
// after merging https://github.com/vuejs/vue-router/pull/2771 we
|
|
|
|
// When the user navigates through history through back/forward buttons
|
|
|
|
// we do not want to throw the error. We only throw it if directly calling
|
|
|
|
// push/replace. That's why it's not included in isError
|
|
|
|
if (!isExtendedError(NavigationDuplicated, err) && isError(err)) { |
|
|
|
// changed after adding errors with
|
|
|
|
// https://github.com/vuejs/vue-router/pull/3047 before that change,
|
|
|
|
// redirect and aborted navigation would produce an err == null
|
|
|
|
if (!isNavigationFailure(err) && isError(err)) { |
|
|
|
if (this$1.errorCbs.length) { |
|
|
|
this$1.errorCbs.forEach(function (cb) { |
|
|
|
cb(err); |
|
|
@ -2125,13 +2216,16 @@ |
|
|
|
} |
|
|
|
onAbort && onAbort(err); |
|
|
|
}; |
|
|
|
var lastRouteIndex = route.matched.length - 1; |
|
|
|
var lastCurrentIndex = current.matched.length - 1; |
|
|
|
if ( |
|
|
|
isSameRoute(route, current) && |
|
|
|
// in the case the route map has been dynamically appended to
|
|
|
|
route.matched.length === current.matched.length |
|
|
|
lastRouteIndex === lastCurrentIndex && |
|
|
|
route.matched[lastRouteIndex] === current.matched[lastCurrentIndex] |
|
|
|
) { |
|
|
|
this.ensureURL(); |
|
|
|
return abort(new NavigationDuplicated(route)) |
|
|
|
return abort(createNavigationDuplicatedError(current, route)) |
|
|
|
} |
|
|
|
|
|
|
|
var ref = resolveQueue( |
|
|
@ -2158,12 +2252,15 @@ |
|
|
|
this.pending = route; |
|
|
|
var iterator = function (hook, next) { |
|
|
|
if (this$1.pending !== route) { |
|
|
|
return abort() |
|
|
|
return abort(createNavigationCancelledError(current, route)) |
|
|
|
} |
|
|
|
try { |
|
|
|
hook(route, current, function (to) { |
|
|
|
if (to === false || isError(to)) { |
|
|
|
if (to === false) { |
|
|
|
// next(false) -> abort navigation, ensure current URL
|
|
|
|
this$1.ensureURL(true); |
|
|
|
abort(createNavigationAbortedError(current, route)); |
|
|
|
} else if (isError(to)) { |
|
|
|
this$1.ensureURL(true); |
|
|
|
abort(to); |
|
|
|
} else if ( |
|
|
@ -2172,7 +2269,7 @@ |
|
|
|
(typeof to.path === 'string' || typeof to.name === 'string')) |
|
|
|
) { |
|
|
|
// next('/') or next({ path: '/' }) -> redirect
|
|
|
|
abort(); |
|
|
|
abort(createNavigationRedirectedError(current, route)); |
|
|
|
if (typeof to === 'object' && to.replace) { |
|
|
|
this$1.replace(to); |
|
|
|
} else { |
|
|
@ -2197,7 +2294,7 @@ |
|
|
|
var queue = enterGuards.concat(this$1.router.resolveHooks); |
|
|
|
runQueue(queue, iterator, function () { |
|
|
|
if (this$1.pending !== route) { |
|
|
|
return abort() |
|
|
|
return abort(createNavigationCancelledError(current, route)) |
|
|
|
} |
|
|
|
this$1.pending = null; |
|
|
|
onComplete(route); |
|
|
@ -2213,12 +2310,19 @@ |
|
|
|
}; |
|
|
|
|
|
|
|
History.prototype.updateRoute = function updateRoute (route) { |
|
|
|
var prev = this.current; |
|
|
|
this.current = route; |
|
|
|
this.cb && this.cb(route); |
|
|
|
this.router.afterHooks.forEach(function (hook) { |
|
|
|
hook && hook(route, prev); |
|
|
|
}; |
|
|
|
|
|
|
|
History.prototype.setupListeners = function setupListeners () { |
|
|
|
// Default implementation is empty
|
|
|
|
}; |
|
|
|
|
|
|
|
History.prototype.teardownListeners = function teardownListeners () { |
|
|
|
this.listeners.forEach(function (cleanupListener) { |
|
|
|
cleanupListener(); |
|
|
|
}); |
|
|
|
this.listeners = []; |
|
|
|
}; |
|
|
|
|
|
|
|
function normalizeBase (base) { |
|
|
@ -2363,25 +2467,37 @@ |
|
|
|
|
|
|
|
var HTML5History = /*@__PURE__*/(function (History) { |
|
|
|
function HTML5History (router, base) { |
|
|
|
History.call(this, router, base); |
|
|
|
|
|
|
|
this._startLocation = getLocation(this.base); |
|
|
|
} |
|
|
|
|
|
|
|
if ( History ) HTML5History.__proto__ = History; |
|
|
|
HTML5History.prototype = Object.create( History && History.prototype ); |
|
|
|
HTML5History.prototype.constructor = HTML5History; |
|
|
|
|
|
|
|
HTML5History.prototype.setupListeners = function setupListeners () { |
|
|
|
var this$1 = this; |
|
|
|
|
|
|
|
History.call(this, router, base); |
|
|
|
if (this.listeners.length > 0) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var router = this.router; |
|
|
|
var expectScroll = router.options.scrollBehavior; |
|
|
|
var supportsScroll = supportsPushState && expectScroll; |
|
|
|
|
|
|
|
if (supportsScroll) { |
|
|
|
setupScroll(); |
|
|
|
this.listeners.push(setupScroll()); |
|
|
|
} |
|
|
|
|
|
|
|
var initLocation = getLocation(this.base); |
|
|
|
window.addEventListener('popstate', function (e) { |
|
|
|
var handleRoutingEvent = function () { |
|
|
|
var current = this$1.current; |
|
|
|
|
|
|
|
// Avoiding first `popstate` event dispatched in some browsers but first
|
|
|
|
// history route not updated since async guard at the same time.
|
|
|
|
var location = getLocation(this$1.base); |
|
|
|
if (this$1.current === START && location === initLocation) { |
|
|
|
if (this$1.current === START && location === this$1._startLocation) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
@ -2390,12 +2506,12 @@ |
|
|
|
handleScroll(router, route, current, true); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
window.addEventListener('popstate', handleRoutingEvent); |
|
|
|
this.listeners.push(function () { |
|
|
|
window.removeEventListener('popstate', handleRoutingEvent); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if ( History ) HTML5History.__proto__ = History; |
|
|
|
HTML5History.prototype = Object.create( History && History.prototype ); |
|
|
|
HTML5History.prototype.constructor = HTML5History; |
|
|
|
}; |
|
|
|
|
|
|
|
HTML5History.prototype.go = function go (n) { |
|
|
|
window.history.go(n); |
|
|
@ -2441,7 +2557,7 @@ |
|
|
|
|
|
|
|
function getLocation (base) { |
|
|
|
var path = decodeURI(window.location.pathname); |
|
|
|
if (base && path.indexOf(base) === 0) { |
|
|
|
if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) { |
|
|
|
path = path.slice(base.length); |
|
|
|
} |
|
|
|
return (path || '/') + window.location.search + window.location.hash |
|
|
@ -2468,31 +2584,40 @@ |
|
|
|
HashHistory.prototype.setupListeners = function setupListeners () { |
|
|
|
var this$1 = this; |
|
|
|
|
|
|
|
if (this.listeners.length > 0) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var router = this.router; |
|
|
|
var expectScroll = router.options.scrollBehavior; |
|
|
|
var supportsScroll = supportsPushState && expectScroll; |
|
|
|
|
|
|
|
if (supportsScroll) { |
|
|
|
setupScroll(); |
|
|
|
this.listeners.push(setupScroll()); |
|
|
|
} |
|
|
|
|
|
|
|
window.addEventListener( |
|
|
|
supportsPushState ? 'popstate' : 'hashchange', |
|
|
|
function () { |
|
|
|
var current = this$1.current; |
|
|
|
if (!ensureSlash()) { |
|
|
|
return |
|
|
|
} |
|
|
|
this$1.transitionTo(getHash(), function (route) { |
|
|
|
if (supportsScroll) { |
|
|
|
handleScroll(this$1.router, route, current, true); |
|
|
|
} |
|
|
|
if (!supportsPushState) { |
|
|
|
replaceHash(route.fullPath); |
|
|
|
} |
|
|
|
}); |
|
|
|
var handleRoutingEvent = function () { |
|
|
|
var current = this$1.current; |
|
|
|
if (!ensureSlash()) { |
|
|
|
return |
|
|
|
} |
|
|
|
this$1.transitionTo(getHash(), function (route) { |
|
|
|
if (supportsScroll) { |
|
|
|
handleScroll(this$1.router, route, current, true); |
|
|
|
} |
|
|
|
if (!supportsPushState) { |
|
|
|
replaceHash(route.fullPath); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
var eventType = supportsPushState ? 'popstate' : 'hashchange'; |
|
|
|
window.addEventListener( |
|
|
|
eventType, |
|
|
|
handleRoutingEvent |
|
|
|
); |
|
|
|
this.listeners.push(function () { |
|
|
|
window.removeEventListener(eventType, handleRoutingEvent); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
HashHistory.prototype.push = function push (location, onComplete, onAbort) { |
|
|
@ -2665,7 +2790,7 @@ |
|
|
|
this$1.updateRoute(route); |
|
|
|
}, |
|
|
|
function (err) { |
|
|
|
if (isExtendedError(NavigationDuplicated, err)) { |
|
|
|
if (isNavigationFailure(err, NavigationFailureType.duplicated)) { |
|
|
|
this$1.index = targetIndex; |
|
|
|
} |
|
|
|
} |
|
|
@ -2686,8 +2811,6 @@ |
|
|
|
|
|
|
|
/* */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var VueRouter = function VueRouter (options) { |
|
|
|
if ( options === void 0 ) options = {}; |
|
|
|
|
|
|
@ -2700,7 +2823,8 @@ |
|
|
|
this.matcher = createMatcher(options.routes || [], this); |
|
|
|
|
|
|
|
var mode = options.mode || 'hash'; |
|
|
|
this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false; |
|
|
|
this.fallback = |
|
|
|
mode === 'history' && !supportsPushState && options.fallback !== false; |
|
|
|
if (this.fallback) { |
|
|
|
mode = 'hash'; |
|
|
|
} |
|
|
@ -2728,11 +2852,7 @@ |
|
|
|
|
|
|
|
var prototypeAccessors = { currentRoute: { configurable: true } }; |
|
|
|
|
|
|
|
VueRouter.prototype.match = function match ( |
|
|
|
raw, |
|
|
|
current, |
|
|
|
redirectedFrom |
|
|
|
) { |
|
|
|
VueRouter.prototype.match = function match (raw, current, redirectedFrom) { |
|
|
|
return this.matcher.match(raw, current, redirectedFrom) |
|
|
|
}; |
|
|
|
|
|
|
@ -2743,11 +2863,12 @@ |
|
|
|
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." |
|
|
|
); |
|
|
|
|
|
|
|
assert( |
|
|
|
install.installed, |
|
|
|
"not installed. Make sure to call `Vue.use(VueRouter)` " + |
|
|
|
"before creating root instance." |
|
|
|
); |
|
|
|
|
|
|
|
this.apps.push(app); |
|
|
|
|
|
|
@ -2760,6 +2881,12 @@ |
|
|
|
// ensure we still have a main app or null if no apps
|
|
|
|
// we do not release the router so it can be reused
|
|
|
|
if (this$1.app === app) { this$1.app = this$1.apps[0] || null; } |
|
|
|
|
|
|
|
if (!this$1.app) { |
|
|
|
// clean up event listeners
|
|
|
|
// https://github.com/vuejs/vue-router/issues/2341
|
|
|
|
this$1.history.teardownListeners(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// main app previously initialized
|
|
|
@ -2772,16 +2899,24 @@ |
|
|
|
|
|
|
|
var history = this.history; |
|
|
|
|
|
|
|
if (history instanceof HTML5History) { |
|
|
|
history.transitionTo(history.getCurrentLocation()); |
|
|
|
} else if (history instanceof HashHistory) { |
|
|
|
var setupHashListener = function () { |
|
|
|
if (history instanceof HTML5History || history instanceof HashHistory) { |
|
|
|
var handleInitialScroll = function (routeOrError) { |
|
|
|
var from = history.current; |
|
|
|
var expectScroll = this$1.options.scrollBehavior; |
|
|
|
var supportsScroll = supportsPushState && expectScroll; |
|
|
|
|
|
|
|
if (supportsScroll && 'fullPath' in routeOrError) { |
|
|
|
handleScroll(this$1, routeOrError, from, false); |
|
|
|
} |
|
|
|
}; |
|
|
|
var setupListeners = function (routeOrError) { |
|
|
|
history.setupListeners(); |
|
|
|
handleInitialScroll(routeOrError); |
|
|
|
}; |
|
|
|
history.transitionTo( |
|
|
|
history.getCurrentLocation(), |
|
|
|
setupHashListener, |
|
|
|
setupHashListener |
|
|
|
setupListeners, |
|
|
|
setupListeners |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
@ -2859,11 +2994,14 @@ |
|
|
|
if (!route) { |
|
|
|
return [] |
|
|
|
} |
|
|
|
return [].concat.apply([], route.matched.map(function (m) { |
|
|
|
return Object.keys(m.components).map(function (key) { |
|
|
|
return m.components[key] |
|
|
|
return [].concat.apply( |
|
|
|
[], |
|
|
|
route.matched.map(function (m) { |
|
|
|
return Object.keys(m.components).map(function (key) { |
|
|
|
return m.components[key] |
|
|
|
}) |
|
|
|
}) |
|
|
|
})) |
|
|
|
) |
|
|
|
}; |
|
|
|
|
|
|
|
VueRouter.prototype.resolve = function resolve ( |
|
|
@ -2872,12 +3010,7 @@ |
|
|
|
append |
|
|
|
) { |
|
|
|
current = current || this.history.current; |
|
|
|
var location = normalizeLocation( |
|
|
|
to, |
|
|
|
current, |
|
|
|
append, |
|
|
|
this |
|
|
|
); |
|
|
|
var location = normalizeLocation(to, current, append, this); |
|
|
|
var route = this.match(location, current); |
|
|
|
var fullPath = route.redirectedFrom || route.fullPath; |
|
|
|
var base = this.history.base; |
|
|
@ -2915,7 +3048,9 @@ |
|
|
|
} |
|
|
|
|
|
|
|
VueRouter.install = install; |
|
|
|
VueRouter.version = '3.1.6'; |
|
|
|
VueRouter.version = '3.4.3'; |
|
|
|
VueRouter.isNavigationFailure = isNavigationFailure; |
|
|
|
VueRouter.NavigationFailureType = NavigationFailureType; |
|
|
|
|
|
|
|
if (inBrowser && window.Vue) { |
|
|
|
window.Vue.use(VueRouter); |