diff --git a/dist/vue-router.common.js b/dist/vue-router.common.js index 8a84ee94c..c63f38057 100644 --- a/dist/vue-router.common.js +++ b/dist/vue-router.common.js @@ -1,5 +1,5 @@ /*! - * vue-router v3.4.5 + * vue-router v3.4.6 * (c) 2020 Evan You * @license MIT */ @@ -26,158 +26,6 @@ function extend (a, b) { return a } -var View = { - name: 'RouterView', - functional: true, - props: { - name: { - type: String, - default: 'default' - } - }, - render: function render (_, ref) { - var props = ref.props; - var children = ref.children; - var parent = ref.parent; - var data = ref.data; - - // used by devtools to display a router-view badge - data.routerView = true; - - // directly use parent context's createElement() function - // so that components rendered by router-view can resolve named slots - var h = parent.$createElement; - var name = props.name; - var route = parent.$route; - var cache = parent._routerViewCache || (parent._routerViewCache = {}); - - // determine current view depth, also check to see if the tree - // has been toggled inactive but kept-alive. - var depth = 0; - var inactive = false; - while (parent && parent._routerRoot !== parent) { - var vnodeData = parent.$vnode ? parent.$vnode.data : {}; - if (vnodeData.routerView) { - depth++; - } - if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { - inactive = true; - } - parent = parent.$parent; - } - data.routerViewDepth = depth; - - // render previous view if the tree is inactive and kept-alive - if (inactive) { - var cachedData = cache[name]; - var cachedComponent = cachedData && cachedData.component; - if (cachedComponent) { - // #2301 - // pass props - if (cachedData.configProps) { - fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); - } - return h(cachedComponent, data, children) - } else { - // render previous empty view - return h() - } - } - - var matched = route.matched[depth]; - var component = matched && matched.components[name]; - - // render empty node if no matched route or no config component - if (!matched || !component) { - cache[name] = null; - return h() - } - - // cache component - cache[name] = { component: component }; - - // attach instance registration hook - // this will be called in the instance's injected lifecycle hooks - data.registerRouteInstance = function (vm, val) { - // val could be undefined for unregistration - var current = matched.instances[name]; - if ( - (val && current !== vm) || - (!val && current === vm) - ) { - matched.instances[name] = val; - } - } - - // also register instance in prepatch hook - // in case the same component instance is reused across different routes - ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { - matched.instances[name] = vnode.componentInstance; - }; - - // register instance in init hook - // in case kept-alive component be actived when routes changed - data.hook.init = function (vnode) { - if (vnode.data.keepAlive && - vnode.componentInstance && - vnode.componentInstance !== matched.instances[name] - ) { - matched.instances[name] = vnode.componentInstance; - } - }; - - var configProps = matched.props && matched.props[name]; - // save route and configProps in cache - if (configProps) { - extend(cache[name], { - route: route, - configProps: configProps - }); - fillPropsinData(component, data, route, configProps); - } - - return h(component, data, children) - } -}; - -function fillPropsinData (component, data, route, configProps) { - // resolve props - var propsToPass = data.props = resolveProps(route, configProps); - if (propsToPass) { - // clone to prevent mutation - propsToPass = data.props = extend({}, propsToPass); - // pass non-declared props as attrs - var attrs = data.attrs = data.attrs || {}; - for (var key in propsToPass) { - if (!component.props || !(key in component.props)) { - attrs[key] = propsToPass[key]; - delete propsToPass[key]; - } - } - } -} - -function resolveProps (route, config) { - switch (typeof config) { - case 'undefined': - return - case 'object': - return config - case 'function': - return config(route) - case 'boolean': - return config ? route.params : undefined - default: - if (process.env.NODE_ENV !== 'production') { - warn( - false, - "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + - "expecting an object, function or boolean." - ); - } - } -} - /* */ var encodeReserveRE = /[!'()*]/g; @@ -191,7 +39,16 @@ var encode = function (str) { return encodeURIComponent(str) .replace(encodeReserveRE, encodeReserveReplacer) .replace(commaRE, ','); }; -var decode = decodeURIComponent; +function decode (str) { + try { + return decodeURIComponent(str) + } catch (err) { + if (process.env.NODE_ENV !== 'production') { + warn(false, ("Error decoding \"" + str + "\". Leaving it intact.")); + } + } + return str +} function resolveQuery ( query, @@ -421,6 +278,178 @@ function queryIncludes (current, target) { return true } +function handleRouteEntered (route) { + for (var i = 0; i < route.matched.length; i++) { + var record = route.matched[i]; + for (var name in record.instances) { + var instance = record.instances[name]; + var cbs = record.enteredCbs[name]; + if (!instance || !cbs) { continue } + delete record.enteredCbs[name]; + for (var i$1 = 0; i$1 < cbs.length; i$1++) { + if (!instance._isBeingDestroyed) { cbs[i$1](instance); } + } + } + } +} + +var View = { + name: 'RouterView', + functional: true, + props: { + name: { + type: String, + default: 'default' + } + }, + render: function render (_, ref) { + var props = ref.props; + var children = ref.children; + var parent = ref.parent; + var data = ref.data; + + // used by devtools to display a router-view badge + data.routerView = true; + + // directly use parent context's createElement() function + // so that components rendered by router-view can resolve named slots + var h = parent.$createElement; + var name = props.name; + var route = parent.$route; + var cache = parent._routerViewCache || (parent._routerViewCache = {}); + + // determine current view depth, also check to see if the tree + // has been toggled inactive but kept-alive. + var depth = 0; + var inactive = false; + while (parent && parent._routerRoot !== parent) { + var vnodeData = parent.$vnode ? parent.$vnode.data : {}; + if (vnodeData.routerView) { + depth++; + } + if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { + inactive = true; + } + parent = parent.$parent; + } + data.routerViewDepth = depth; + + // render previous view if the tree is inactive and kept-alive + if (inactive) { + var cachedData = cache[name]; + var cachedComponent = cachedData && cachedData.component; + if (cachedComponent) { + // #2301 + // pass props + if (cachedData.configProps) { + fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); + } + return h(cachedComponent, data, children) + } else { + // render previous empty view + return h() + } + } + + var matched = route.matched[depth]; + var component = matched && matched.components[name]; + + // render empty node if no matched route or no config component + if (!matched || !component) { + cache[name] = null; + return h() + } + + // cache component + cache[name] = { component: component }; + + // attach instance registration hook + // this will be called in the instance's injected lifecycle hooks + data.registerRouteInstance = function (vm, val) { + // val could be undefined for unregistration + var current = matched.instances[name]; + if ( + (val && current !== vm) || + (!val && current === vm) + ) { + matched.instances[name] = val; + } + } + + // also register instance in prepatch hook + // in case the same component instance is reused across different routes + ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { + matched.instances[name] = vnode.componentInstance; + }; + + // register instance in init hook + // in case kept-alive component be actived when routes changed + data.hook.init = function (vnode) { + if (vnode.data.keepAlive && + vnode.componentInstance && + vnode.componentInstance !== matched.instances[name] + ) { + matched.instances[name] = vnode.componentInstance; + } + + // if the route transition has already been confirmed then we weren't + // able to call the cbs during confirmation as the component was not + // registered yet, so we call it here. + handleRouteEntered(route); + }; + + var configProps = matched.props && matched.props[name]; + // save route and configProps in cache + if (configProps) { + extend(cache[name], { + route: route, + configProps: configProps + }); + fillPropsinData(component, data, route, configProps); + } + + return h(component, data, children) + } +}; + +function fillPropsinData (component, data, route, configProps) { + // resolve props + var propsToPass = data.props = resolveProps(route, configProps); + if (propsToPass) { + // clone to prevent mutation + propsToPass = data.props = extend({}, propsToPass); + // pass non-declared props as attrs + var attrs = data.attrs = data.attrs || {}; + for (var key in propsToPass) { + if (!component.props || !(key in component.props)) { + attrs[key] = propsToPass[key]; + delete propsToPass[key]; + } + } + } +} + +function resolveProps (route, config) { + switch (typeof config) { + case 'undefined': + return + case 'object': + return config + case 'function': + return config(route) + case 'boolean': + return config ? route.params : undefined + default: + if (process.env.NODE_ENV !== 'production') { + warn( + false, + "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + + "expecting an object, function or boolean." + ); + } + } +} + /* */ function resolvePath ( @@ -1351,6 +1380,7 @@ function addRouteRecord ( regex: compileRouteRegex(normalizedPath, pathToRegexpOptions), components: route.components || { default: route.component }, instances: {}, + enteredCbs: {}, name: name, parent: parent, matchAs: matchAs, @@ -1640,7 +1670,14 @@ function matchRoute ( path, params ) { - var m = path.match(regex); + var m; + try { + m = decodeURI(path).match(regex); + } catch (err) { + if (process.env.NODE_ENV !== 'production') { + warn(false, ("Error decoding \"" + path + "\". Leaving it intact.")); + } + } if (!m) { return false @@ -1650,10 +1687,9 @@ function matchRoute ( for (var i = 1, len = m.length; i < len; ++i) { var key = regex.keys[i - 1]; - var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]; if (key) { // Fix #1994: using * with props: true generates a param named 0 - params[key.name || 'pathMatch'] = val; + params[key.name || 'pathMatch'] = m[i]; } } @@ -2281,11 +2317,9 @@ History.prototype.confirmTransition = function confirmTransition (route, onCompl }; runQueue(queue, iterator, function () { - var postEnterCbs = []; - var isValid = function () { return this$1.current === route; }; // wait until async components are resolved before // extracting in-component enter guards - var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid); + var enterGuards = extractEnterGuards(activated); var queue = enterGuards.concat(this$1.router.resolveHooks); runQueue(queue, iterator, function () { if (this$1.pending !== route) { @@ -2295,9 +2329,7 @@ History.prototype.confirmTransition = function confirmTransition (route, onCompl onComplete(route); if (this$1.router.app) { this$1.router.app.$nextTick(function () { - postEnterCbs.forEach(function (cb) { - cb(); - }); + handleRouteEntered(route); }); } }); @@ -2410,15 +2442,13 @@ function bindGuard (guard, instance) { } function extractEnterGuards ( - activated, - cbs, - isValid + activated ) { return extractGuards( activated, 'beforeRouteEnter', function (guard, _, match, key) { - return bindEnterGuard(guard, match, key, cbs, isValid) + return bindEnterGuard(guard, match, key) } ) } @@ -2426,45 +2456,21 @@ function extractEnterGuards ( function bindEnterGuard ( guard, match, - key, - cbs, - isValid + key ) { return function routeEnterGuard (to, from, next) { return guard(to, from, function (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); - }); + if (!match.enteredCbs[key]) { + match.enteredCbs[key] = []; + } + match.enteredCbs[key].push(cb); } next(cb); }) } } -function poll ( - cb, // somehow flow cannot infer this is a function - instances, - key, - isValid -) { - if ( - instances[key] && - !instances[key]._isBeingDestroyed // do not reuse being destroyed instance - ) { - cb(instances[key]); - } else if (isValid()) { - setTimeout(function () { - poll(cb, instances, key, isValid); - }, 16); - } -} - /* */ var HTML5History = /*@__PURE__*/(function (History) { @@ -2558,7 +2564,7 @@ var HTML5History = /*@__PURE__*/(function (History) { }(History)); function getLocation (base) { - var path = decodeURI(window.location.pathname); + var path = window.location.pathname; if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) { path = path.slice(base.length); } @@ -2698,18 +2704,6 @@ function getHash () { if (index < 0) { return '' } href = href.slice(index + 1); - // decode the hash but not the search or hash - // as search(query) is already decoded - // https://github.com/vuejs/vue-router/issues/2708 - var searchIndex = href.indexOf('?'); - if (searchIndex < 0) { - var hashIndex = href.indexOf('#'); - if (hashIndex > -1) { - href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); - } else { href = decodeURI(href); } - } else { - href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); - } return href } @@ -3050,7 +3044,7 @@ function createHref (base, fullPath, mode) { } VueRouter.install = install; -VueRouter.version = '3.4.5'; +VueRouter.version = '3.4.6'; VueRouter.isNavigationFailure = isNavigationFailure; VueRouter.NavigationFailureType = NavigationFailureType; diff --git a/dist/vue-router.esm.browser.js b/dist/vue-router.esm.browser.js index 52000e0be..f353f4870 100644 --- a/dist/vue-router.esm.browser.js +++ b/dist/vue-router.esm.browser.js @@ -1,5 +1,5 @@ /*! - * vue-router v3.4.5 + * vue-router v3.4.6 * (c) 2020 Evan You * @license MIT */ @@ -24,153 +24,6 @@ function extend (a, b) { return a } -var View = { - name: 'RouterView', - functional: true, - props: { - name: { - type: String, - default: 'default' - } - }, - render (_, { props, children, parent, data }) { - // used by devtools to display a router-view badge - data.routerView = true; - - // directly use parent context's createElement() function - // so that components rendered by router-view can resolve named slots - const h = parent.$createElement; - const name = props.name; - const route = parent.$route; - const cache = parent._routerViewCache || (parent._routerViewCache = {}); - - // determine current view depth, also check to see if the tree - // has been toggled inactive but kept-alive. - let depth = 0; - let inactive = false; - while (parent && parent._routerRoot !== parent) { - const vnodeData = parent.$vnode ? parent.$vnode.data : {}; - if (vnodeData.routerView) { - depth++; - } - if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { - inactive = true; - } - parent = parent.$parent; - } - data.routerViewDepth = depth; - - // render previous view if the tree is inactive and kept-alive - if (inactive) { - const cachedData = cache[name]; - const cachedComponent = cachedData && cachedData.component; - if (cachedComponent) { - // #2301 - // pass props - if (cachedData.configProps) { - fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); - } - return h(cachedComponent, data, children) - } else { - // render previous empty view - return h() - } - } - - const matched = route.matched[depth]; - const component = matched && matched.components[name]; - - // render empty node if no matched route or no config component - if (!matched || !component) { - cache[name] = null; - return h() - } - - // cache component - cache[name] = { component }; - - // attach instance registration hook - // this will be called in the instance's injected lifecycle hooks - data.registerRouteInstance = (vm, val) => { - // val could be undefined for unregistration - const current = matched.instances[name]; - if ( - (val && current !== vm) || - (!val && current === vm) - ) { - matched.instances[name] = val; - } - } - - // also register instance in prepatch hook - // in case the same component instance is reused across different routes - ;(data.hook || (data.hook = {})).prepatch = (_, vnode) => { - matched.instances[name] = vnode.componentInstance; - }; - - // register instance in init hook - // in case kept-alive component be actived when routes changed - data.hook.init = (vnode) => { - if (vnode.data.keepAlive && - vnode.componentInstance && - vnode.componentInstance !== matched.instances[name] - ) { - matched.instances[name] = vnode.componentInstance; - } - }; - - const configProps = matched.props && matched.props[name]; - // save route and configProps in cache - if (configProps) { - extend(cache[name], { - route, - configProps - }); - fillPropsinData(component, data, route, configProps); - } - - return h(component, data, children) - } -}; - -function fillPropsinData (component, data, route, configProps) { - // resolve props - let propsToPass = data.props = resolveProps(route, configProps); - if (propsToPass) { - // clone to prevent mutation - propsToPass = data.props = extend({}, propsToPass); - // pass non-declared props as attrs - const attrs = data.attrs = data.attrs || {}; - for (const key in propsToPass) { - if (!component.props || !(key in component.props)) { - attrs[key] = propsToPass[key]; - delete propsToPass[key]; - } - } - } -} - -function resolveProps (route, config) { - switch (typeof config) { - case 'undefined': - return - case 'object': - return config - case 'function': - return config(route) - case 'boolean': - return config ? route.params : undefined - default: - { - warn( - false, - `props in "${route.path}" is a ${typeof config}, ` + - `expecting an object, function or boolean.` - ); - } - } -} - /* */ const encodeReserveRE = /[!'()*]/g; @@ -185,7 +38,16 @@ const encode = str => .replace(encodeReserveRE, encodeReserveReplacer) .replace(commaRE, ','); -const decode = decodeURIComponent; +function decode (str) { + try { + return decodeURIComponent(str) + } catch (err) { + { + warn(false, `Error decoding "${str}". Leaving it intact.`); + } + } + return str +} function resolveQuery ( query, @@ -406,6 +268,173 @@ function queryIncludes (current, target) { return true } +function handleRouteEntered (route) { + for (let i = 0; i < route.matched.length; i++) { + const record = route.matched[i]; + for (const name in record.instances) { + const instance = record.instances[name]; + const cbs = record.enteredCbs[name]; + if (!instance || !cbs) continue + delete record.enteredCbs[name]; + for (let i = 0; i < cbs.length; i++) { + if (!instance._isBeingDestroyed) cbs[i](instance); + } + } + } +} + +var View = { + name: 'RouterView', + functional: true, + props: { + name: { + type: String, + default: 'default' + } + }, + render (_, { props, children, parent, data }) { + // used by devtools to display a router-view badge + data.routerView = true; + + // directly use parent context's createElement() function + // so that components rendered by router-view can resolve named slots + const h = parent.$createElement; + const name = props.name; + const route = parent.$route; + const cache = parent._routerViewCache || (parent._routerViewCache = {}); + + // determine current view depth, also check to see if the tree + // has been toggled inactive but kept-alive. + let depth = 0; + let inactive = false; + while (parent && parent._routerRoot !== parent) { + const vnodeData = parent.$vnode ? parent.$vnode.data : {}; + if (vnodeData.routerView) { + depth++; + } + if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { + inactive = true; + } + parent = parent.$parent; + } + data.routerViewDepth = depth; + + // render previous view if the tree is inactive and kept-alive + if (inactive) { + const cachedData = cache[name]; + const cachedComponent = cachedData && cachedData.component; + if (cachedComponent) { + // #2301 + // pass props + if (cachedData.configProps) { + fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); + } + return h(cachedComponent, data, children) + } else { + // render previous empty view + return h() + } + } + + const matched = route.matched[depth]; + const component = matched && matched.components[name]; + + // render empty node if no matched route or no config component + if (!matched || !component) { + cache[name] = null; + return h() + } + + // cache component + cache[name] = { component }; + + // attach instance registration hook + // this will be called in the instance's injected lifecycle hooks + data.registerRouteInstance = (vm, val) => { + // val could be undefined for unregistration + const current = matched.instances[name]; + if ( + (val && current !== vm) || + (!val && current === vm) + ) { + matched.instances[name] = val; + } + } + + // also register instance in prepatch hook + // in case the same component instance is reused across different routes + ;(data.hook || (data.hook = {})).prepatch = (_, vnode) => { + matched.instances[name] = vnode.componentInstance; + }; + + // register instance in init hook + // in case kept-alive component be actived when routes changed + data.hook.init = (vnode) => { + if (vnode.data.keepAlive && + vnode.componentInstance && + vnode.componentInstance !== matched.instances[name] + ) { + matched.instances[name] = vnode.componentInstance; + } + + // if the route transition has already been confirmed then we weren't + // able to call the cbs during confirmation as the component was not + // registered yet, so we call it here. + handleRouteEntered(route); + }; + + const configProps = matched.props && matched.props[name]; + // save route and configProps in cache + if (configProps) { + extend(cache[name], { + route, + configProps + }); + fillPropsinData(component, data, route, configProps); + } + + return h(component, data, children) + } +}; + +function fillPropsinData (component, data, route, configProps) { + // resolve props + let propsToPass = data.props = resolveProps(route, configProps); + if (propsToPass) { + // clone to prevent mutation + propsToPass = data.props = extend({}, propsToPass); + // pass non-declared props as attrs + const attrs = data.attrs = data.attrs || {}; + for (const key in propsToPass) { + if (!component.props || !(key in component.props)) { + attrs[key] = propsToPass[key]; + delete propsToPass[key]; + } + } + } +} + +function resolveProps (route, config) { + switch (typeof config) { + case 'undefined': + return + case 'object': + return config + case 'function': + return config(route) + case 'boolean': + return config ? route.params : undefined + default: + { + warn( + false, + `props in "${route.path}" is a ${typeof config}, ` + + `expecting an object, function or boolean.` + ); + } + } +} + /* */ function resolvePath ( @@ -1332,6 +1361,7 @@ function addRouteRecord ( regex: compileRouteRegex(normalizedPath, pathToRegexpOptions), components: route.components || { default: route.component }, instances: {}, + enteredCbs: {}, name, parent, matchAs, @@ -1617,7 +1647,14 @@ function matchRoute ( path, params ) { - const m = path.match(regex); + let m; + try { + m = decodeURI(path).match(regex); + } catch (err) { + { + warn(false, `Error decoding "${path}". Leaving it intact.`); + } + } if (!m) { return false @@ -1627,10 +1664,9 @@ function matchRoute ( for (let i = 1, len = m.length; i < len; ++i) { const key = regex.keys[i - 1]; - const val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]; if (key) { // Fix #1994: using * with props: true generates a param named 0 - params[key.name || 'pathMatch'] = val; + params[key.name || 'pathMatch'] = m[i]; } } @@ -2273,11 +2309,9 @@ class History { }; runQueue(queue, iterator, () => { - const postEnterCbs = []; - const isValid = () => this.current === route; // wait until async components are resolved before // extracting in-component enter guards - const enterGuards = extractEnterGuards(activated, postEnterCbs, isValid); + const enterGuards = extractEnterGuards(activated); const queue = enterGuards.concat(this.router.resolveHooks); runQueue(queue, iterator, () => { if (this.pending !== route) { @@ -2287,9 +2321,7 @@ class History { onComplete(route); if (this.router.app) { this.router.app.$nextTick(() => { - postEnterCbs.forEach(cb => { - cb(); - }); + handleRouteEntered(route); }); } }); @@ -2403,15 +2435,13 @@ function bindGuard (guard, instance) { } function extractEnterGuards ( - activated, - cbs, - isValid + activated ) { return extractGuards( activated, 'beforeRouteEnter', (guard, _, match, key) => { - return bindEnterGuard(guard, match, key, cbs, isValid) + return bindEnterGuard(guard, match, key) } ) } @@ -2419,45 +2449,21 @@ function extractEnterGuards ( function bindEnterGuard ( guard, match, - key, - cbs, - isValid + key ) { return function routeEnterGuard (to, from, next) { return guard(to, from, 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); - }); + if (!match.enteredCbs[key]) { + match.enteredCbs[key] = []; + } + match.enteredCbs[key].push(cb); } next(cb); }) } } -function poll ( - cb, // somehow flow cannot infer this is a function - instances, - key, - isValid -) { - if ( - instances[key] && - !instances[key]._isBeingDestroyed // do not reuse being destroyed instance - ) { - cb(instances[key]); - } else if (isValid()) { - setTimeout(() => { - poll(cb, instances, key, isValid); - }, 16); - } -} - /* */ class HTML5History extends History { @@ -2539,7 +2545,7 @@ class HTML5History extends History { } function getLocation (base) { - let path = decodeURI(window.location.pathname); + let path = window.location.pathname; if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) { path = path.slice(base.length); } @@ -2665,18 +2671,6 @@ function getHash () { if (index < 0) return '' href = href.slice(index + 1); - // decode the hash but not the search or hash - // as search(query) is already decoded - // https://github.com/vuejs/vue-router/issues/2708 - const searchIndex = href.indexOf('?'); - if (searchIndex < 0) { - const hashIndex = href.indexOf('#'); - if (hashIndex > -1) { - href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); - } else href = decodeURI(href); - } else { - href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); - } return href } @@ -3016,7 +3010,7 @@ function createHref (base, fullPath, mode) { } VueRouter.install = install; -VueRouter.version = '3.4.5'; +VueRouter.version = '3.4.6'; VueRouter.isNavigationFailure = isNavigationFailure; VueRouter.NavigationFailureType = NavigationFailureType; diff --git a/dist/vue-router.esm.browser.min.js b/dist/vue-router.esm.browser.min.js index f370d8045..d8c822a62 100644 --- a/dist/vue-router.esm.browser.min.js +++ b/dist/vue-router.esm.browser.min.js @@ -1,6 +1,6 @@ /*! - * vue-router v3.4.5 + * vue-router v3.4.6 * (c) 2020 Evan You * @license MIT */ -function t(t,e){for(const n in e)t[n]=e[n];return t}var e={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render(e,{props:r,children:o,parent:i,data:s}){s.routerView=!0;const a=i.$createElement,c=r.name,u=i.$route,h=i._routerViewCache||(i._routerViewCache={});let l=0,p=!1;for(;i&&i._routerRoot!==i;){const t=i.$vnode?i.$vnode.data:{};t.routerView&&l++,t.keepAlive&&i._directInactive&&i._inactive&&(p=!0),i=i.$parent}if(s.routerViewDepth=l,p){const t=h[c],e=t&&t.component;return e?(t.configProps&&n(e,s,t.route,t.configProps),a(e,s,o)):a()}const f=u.matched[l],d=f&&f.components[c];if(!f||!d)return h[c]=null,a();h[c]={component:d},s.registerRouteInstance=(t,e)=>{const n=f.instances[c];(e&&n!==t||!e&&n===t)&&(f.instances[c]=e)},(s.hook||(s.hook={})).prepatch=(t,e)=>{f.instances[c]=e.componentInstance},s.hook.init=t=>{t.data.keepAlive&&t.componentInstance&&t.componentInstance!==f.instances[c]&&(f.instances[c]=t.componentInstance)};const y=f.props&&f.props[c];return y&&(t(h[c],{route:u,configProps:y}),n(d,s,u,y)),a(d,s,o)}};function n(e,n,r,o){let i=n.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(r,o);if(i){i=n.props=t({},i);const r=n.attrs=n.attrs||{};for(const t in i)e.props&&t in e.props||(r[t]=i[t],delete i[t])}}const r=/[!'()*]/g,o=t=>"%"+t.charCodeAt(0).toString(16),i=/%2C/g,s=t=>encodeURIComponent(t).replace(r,o).replace(i,","),a=decodeURIComponent;const c=t=>null==t||"object"==typeof t?t:String(t);function u(t){const e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(t=>{const n=t.replace(/\+/g," ").split("="),r=a(n.shift()),o=n.length>0?a(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){const e=t?Object.keys(t).map(e=>{const n=t[e];if(void 0===n)return"";if(null===n)return s(e);if(Array.isArray(n)){const t=[];return n.forEach(n=>{void 0!==n&&(null===n?t.push(s(e)):t.push(s(e)+"="+s(n)))}),t.join("&")}return s(e)+"="+s(n)}).filter(t=>t.length>0).join("&"):null;return e?`?${e}`:""}const l=/\/?$/;function p(t,e,n,r){const o=r&&r.options.stringifyQuery;let i=e.query||{};try{i=f(i)}catch(t){}const s={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:m(e,o),matched:t?y(t):[]};return n&&(s.redirectedFrom=m(n,o)),Object.freeze(s)}function f(t){if(Array.isArray(t))return t.map(f);if(t&&"object"==typeof t){const e={};for(const n in t)e[n]=f(t[n]);return e}return t}const d=p(null,{path:"/"});function y(t){const e=[];for(;t;)e.unshift(t),t=t.parent;return e}function m({path:t,query:e={},hash:n=""},r){return(t||"/")+(r||h)(e)+n}function g(t,e){return e===d?t===e:!!e&&(t.path&&e.path?t.path.replace(l,"")===e.path.replace(l,"")&&t.hash===e.hash&&w(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&w(t.query,e.query)&&w(t.params,e.params)))}function w(t={},e={}){if(!t||!e)return t===e;const n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(n=>{const r=t[n],o=e[n];return null==r||null==o?r===o:"object"==typeof r&&"object"==typeof o?w(r,o):String(r)===String(o)})}function v(t,e,n){const r=t.charAt(0);if("/"===r)return t;if("?"===r||"#"===r)return e+t;const o=e.split("/");n&&o[o.length-1]||o.pop();const i=t.replace(/^\//,"").split("/");for(let t=0;t=0&&(e=t.slice(r),t=t.slice(0,r));const o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}(i.path||""),a=n&&n.path||"/",h=s.path?v(s.path,a,r||i.append):a,l=function(t,e={},n){const r=n||u;let o;try{o=r(t||"")}catch(t){o={}}for(const t in e){const n=e[t];o[t]=Array.isArray(n)?n.map(c):c(n)}return o}(s.query,i.query,o&&o.options.parseQuery);let p=i.hash||s.hash;return p&&"#"!==p.charAt(0)&&(p=`#${p}`),{_normalized:!0,path:h,query:l,hash:p}}const B=[String,Object],H=[String,Array],F=()=>{};var N={name:"RouterLink",props:{to:{type:B,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,ariaCurrentValue:{type:String,default:"page"},event:{type:H,default:"click"}},render(e){const n=this.$router,r=this.$route,{location:o,route:i,href:s}=n.resolve(this.to,r,this.append),a={},c=n.options.linkActiveClass,u=n.options.linkExactActiveClass,h=null==c?"router-link-active":c,f=null==u?"router-link-exact-active":u,d=null==this.activeClass?h:this.activeClass,y=null==this.exactActiveClass?f:this.exactActiveClass,m=i.redirectedFrom?p(null,V(i.redirectedFrom),null,n):i;a[y]=g(r,m),a[d]=this.exact?a[y]:function(t,e){return 0===t.path.replace(l,"/").indexOf(e.path.replace(l,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(const n in e)if(!(n in t))return!1;return!0}(t.query,e.query)}(r,m);const w=a[y]?this.ariaCurrentValue:null,v=t=>{z(t)&&(this.replace?n.replace(o,F):n.push(o,F))},b={click:z};Array.isArray(this.event)?this.event.forEach(t=>{b[t]=v}):b[this.event]=v;const x={class:a},R=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:s,route:i,navigate:v,isActive:a[d],isExactActive:a[y]});if(R){if(1===R.length)return R[0];if(R.length>1||!R.length)return 0===R.length?e():e("span",{},R)}if("a"===this.tag)x.on=b,x.attrs={href:s,"aria-current":w};else{const e=function t(e){if(e){let n;for(let r=0;r{!function t(e,n,r,o,i,s){const{path:a,name:c}=o;const u=o.pathToRegexpOptions||{};const h=function(t,e,n){n||(t=t.replace(/\/$/,""));return"/"===t[0]?t:null==e?t:b(`${e.path}/${t}`)}(a,i,u.strict);"boolean"==typeof o.caseSensitive&&(u.sensitive=o.caseSensitive);const l={path:h,regex:Q(h,u),components:o.components||{default:o.component},instances:{},name:c,parent:i,matchAs:s,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};o.children&&o.children.forEach(o=>{const i=s?b(`${s}/${o.path}`):void 0;t(e,n,r,o,l,i)});n[l.path]||(e.push(l.path),n[l.path]=l);if(void 0!==o.alias){const s=Array.isArray(o.alias)?o.alias:[o.alias];for(let a=0;a!t.optional).map(t=>t.name);if("object"!=typeof c.params&&(c.params={}),i&&"object"==typeof i.params)for(const t in i.params)!(t in c.params)&&e.indexOf(t)>-1&&(c.params[t]=i.params[t]);return c.path=M(t.path,c.params),a(t,c,s)}if(c.path){c.params={};for(let t=0;t{window.removeEventListener("popstate",st)}}function ot(t,e,n,r){if(!t.app)return;const o=t.options.scrollBehavior;o&&t.app.$nextTick(()=>{const i=function(){const t=tt();if(t)return nt[t]}(),s=o.call(t,e,n,r?i:null);s&&("function"==typeof s.then?s.then(t=>{lt(t,i)}).catch(t=>{}):lt(s,i))})}function it(){const t=tt();t&&(nt[t]={x:window.pageXOffset,y:window.pageYOffset})}function st(t){it(),t.state&&t.state.key&&et(t.state.key)}function at(t){return ut(t.x)||ut(t.y)}function ct(t){return{x:ut(t.x)?t.x:window.pageXOffset,y:ut(t.y)?t.y:window.pageYOffset}}function ut(t){return"number"==typeof t}const ht=/^#\d/;function lt(t,e){const n="object"==typeof t;if(n&&"string"==typeof t.selector){const n=ht.test(t.selector)?document.getElementById(t.selector.slice(1)):document.querySelector(t.selector);if(n){let o=t.offset&&"object"==typeof t.offset?t.offset:{};e=function(t,e){const n=document.documentElement.getBoundingClientRect(),r=t.getBoundingClientRect();return{x:r.left-n.left-e.x,y:r.top-n.top-e.y}}(n,o={x:ut((r=o).x)?r.x:0,y:ut(r.y)?r.y:0})}else at(t)&&(e=ct(t))}else n&&at(t)&&(e=ct(t));var r;e&&window.scrollTo(e.x,e.y)}const pt=K&&function(){const t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"function"==typeof window.history.pushState)}();function ft(e,n){it();const r=window.history;try{if(n){const n=t({},r.state);n.key=tt(),r.replaceState(n,"",e)}else r.pushState({key:et(G())},"",e)}catch(t){window.location[n?"replace":"assign"](e)}}function dt(t){ft(t,!0)}function yt(t,e,n){const r=o=>{o>=t.length?n():t[o]?e(t[o],()=>{r(o+1)}):r(o+1)};r(0)}const mt={redirected:2,aborted:4,cancelled:8,duplicated:16};function gt(t,e){return vt(t,e,mt.redirected,`Redirected when going from "${t.fullPath}" to "${function(t){if("string"==typeof t)return t;if("path"in t)return t.path;const e={};return bt.forEach(n=>{n in t&&(e[n]=t[n])}),JSON.stringify(e,null,2)}(e)}" via a navigation guard.`)}function wt(t,e){return vt(t,e,mt.cancelled,`Navigation cancelled from "${t.fullPath}" to "${e.fullPath}" with a new navigation.`)}function vt(t,e,n,r){const o=new Error(r);return o._isRouter=!0,o.from=t,o.to=e,o.type=n,o}const bt=["params","query","hash"];function xt(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function Rt(t,e){return xt(t)&&t._isRouter&&(null==e||t.type===e)}function kt(t){return(e,n,r)=>{let o=!1,i=0,s=null;Et(t,(t,e,n,a)=>{if("function"==typeof t&&void 0===t.cid){o=!0,i++;const e=Ct(e=>{(function(t){return t.__esModule||At&&"Module"===t[Symbol.toStringTag]})(e)&&(e=e.default),t.resolved="function"==typeof e?e:D.extend(e),n.components[a]=e,--i<=0&&r()}),c=Ct(t=>{const e=`Failed to resolve async component ${a}: ${t}`;s||(s=xt(t)?t:new Error(e),r(s))});let u;try{u=t(e,c)}catch(t){c(t)}if(u)if("function"==typeof u.then)u.then(e,c);else{const t=u.component;t&&"function"==typeof t.then&&t.then(e,c)}}}),o||r()}}function Et(t,e){return $t(t.map(t=>Object.keys(t.components).map(n=>e(t.components[n],t.instances[n],t,n))))}function $t(t){return Array.prototype.concat.apply([],t)}const At="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function Ct(t){let e=!1;return function(...n){if(!e)return e=!0,t.apply(this,n)}}class Ot{constructor(t,e){this.router=t,this.base=function(t){if(!t)if(K){const e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=d,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[],this.listeners=[]}listen(t){this.cb=t}onReady(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))}onError(t){this.errorCbs.push(t)}transitionTo(t,e,n){let r;try{r=this.router.match(t,this.current)}catch(t){throw this.errorCbs.forEach(e=>{e(t)}),t}const o=this.current;this.confirmTransition(r,()=>{this.updateRoute(r),e&&e(r),this.ensureURL(),this.router.afterHooks.forEach(t=>{t&&t(r,o)}),this.ready||(this.ready=!0,this.readyCbs.forEach(t=>{t(r)}))},t=>{n&&n(t),t&&!this.ready&&(Rt(t,mt.redirected)&&o===d||(this.ready=!0,this.readyErrorCbs.forEach(e=>{e(t)})))})}confirmTransition(t,e,n){const r=this.current;this.pending=t;const o=t=>{!Rt(t)&&xt(t)&&(this.errorCbs.length?this.errorCbs.forEach(e=>{e(t)}):console.error(t)),n&&n(t)},i=t.matched.length-1,s=r.matched.length-1;if(g(t,r)&&i===s&&t.matched[i]===r.matched[s])return this.ensureURL(),o(function(t,e){const n=vt(t,e,mt.duplicated,`Avoided redundant navigation to current location: "${t.fullPath}".`);return n.name="NavigationDuplicated",n}(r,t));const{updated:a,deactivated:c,activated:u}=function(t,e){let n;const r=Math.max(t.length,e.length);for(n=0;nt.beforeEnter),kt(u)),l=(e,n)=>{if(this.pending!==t)return o(wt(r,t));try{e(t,r,e=>{!1===e?(this.ensureURL(!0),o(function(t,e){return vt(t,e,mt.aborted,`Navigation aborted from "${t.fullPath}" to "${e.fullPath}" via a navigation guard.`)}(r,t))):xt(e)?(this.ensureURL(!0),o(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(o(gt(r,t)),"object"==typeof e&&e.replace?this.replace(e):this.push(e)):n(e)})}catch(t){o(t)}};yt(h,l,()=>{const n=[];yt(function(t,e,n){return St(t,"beforeRouteEnter",(t,r,o,i)=>(function(t,e,n,r,o){return function(i,s,a){return t(i,s,t=>{"function"==typeof t&&r.push(()=>{!function t(e,n,r,o){n[r]&&!n[r]._isBeingDestroyed?e(n[r]):o()&&setTimeout(()=>{t(e,n,r,o)},16)}(t,e.instances,n,o)}),a(t)})}})(t,o,i,e,n))}(u,n,()=>this.current===t).concat(this.router.resolveHooks),l,()=>{if(this.pending!==t)return o(wt(r,t));this.pending=null,e(t),this.router.app&&this.router.app.$nextTick(()=>{n.forEach(t=>{t()})})})})}updateRoute(t){this.current=t,this.cb&&this.cb(t)}setupListeners(){}teardown(){this.listeners.forEach(t=>{t()}),this.listeners=[],this.current=d,this.pending=null}}function St(t,e,n,r){const o=Et(t,(t,r,o,i)=>{const s=function(t,e){"function"!=typeof t&&(t=D.extend(t));return t.options[e]}(t,e);if(s)return Array.isArray(s)?s.map(t=>n(t,r,o,i)):n(s,r,o,i)});return $t(r?o.reverse():o)}function jt(t,e){if(e)return function(){return t.apply(e,arguments)}}class Tt extends Ot{constructor(t,e){super(t,e),this._startLocation=Lt(this.base)}setupListeners(){if(this.listeners.length>0)return;const t=this.router,e=t.options.scrollBehavior,n=pt&&e;n&&this.listeners.push(rt());const r=()=>{const e=this.current,r=Lt(this.base);this.current===d&&r===this._startLocation||this.transitionTo(r,r=>{n&&ot(t,r,e,!0)})};window.addEventListener("popstate",r),this.listeners.push(()=>{window.removeEventListener("popstate",r)})}go(t){window.history.go(t)}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{ft(b(this.base+t.fullPath)),ot(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{dt(b(this.base+t.fullPath)),ot(this.router,t,r,!1),e&&e(t)},n)}ensureURL(t){if(Lt(this.base)!==this.current.fullPath){const e=b(this.base+this.current.fullPath);t?ft(e):dt(e)}}getCurrentLocation(){return Lt(this.base)}}function Lt(t){let e=decodeURI(window.location.pathname);return t&&0===e.toLowerCase().indexOf(t.toLowerCase())&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}class Pt extends Ot{constructor(t,e,n){super(t,e),n&&function(t){const e=Lt(t);if(!/^\/#/.test(e))return window.location.replace(b(t+"/#"+e)),!0}(this.base)||_t()}setupListeners(){if(this.listeners.length>0)return;const t=this.router.options.scrollBehavior,e=pt&&t;e&&this.listeners.push(rt());const n=()=>{const t=this.current;_t()&&this.transitionTo(qt(),n=>{e&&ot(this.router,n,t,!0),pt||Mt(n.fullPath)})},r=pt?"popstate":"hashchange";window.addEventListener(r,n),this.listeners.push(()=>{window.removeEventListener(r,n)})}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{It(t.fullPath),ot(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Mt(t.fullPath),ot(this.router,t,r,!1),e&&e(t)},n)}go(t){window.history.go(t)}ensureURL(t){const e=this.current.fullPath;qt()!==e&&(t?It(e):Mt(e))}getCurrentLocation(){return qt()}}function _t(){const t=qt();return"/"===t.charAt(0)||(Mt("/"+t),!1)}function qt(){let t=window.location.href;const e=t.indexOf("#");if(e<0)return"";const n=(t=t.slice(e+1)).indexOf("?");if(n<0){const e=t.indexOf("#");t=e>-1?decodeURI(t.slice(0,e))+t.slice(e):decodeURI(t)}else t=decodeURI(t.slice(0,n))+t.slice(n);return t}function Ut(t){const e=window.location.href,n=e.indexOf("#");return`${n>=0?e.slice(0,n):e}#${t}`}function It(t){pt?ft(Ut(t)):window.location.hash=t}function Mt(t){pt?dt(Ut(t)):window.location.replace(Ut(t))}class Vt extends Ot{constructor(t,e){super(t,e),this.stack=[],this.index=-1}push(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index+1).concat(t),this.index++,e&&e(t)},n)}replace(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index).concat(t),e&&e(t)},n)}go(t){const e=this.index+t;if(e<0||e>=this.stack.length)return;const n=this.stack[e];this.confirmTransition(n,()=>{const t=this.current;this.index=e,this.updateRoute(n),this.router.afterHooks.forEach(e=>{e&&e(n,t)})},t=>{Rt(t,mt.duplicated)&&(this.index=e)})}getCurrentLocation(){const t=this.stack[this.stack.length-1];return t?t.fullPath:"/"}ensureURL(){}}class Bt{constructor(t={}){this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=X(t.routes||[],this);let e=t.mode||"hash";switch(this.fallback="history"===e&&!pt&&!1!==t.fallback,this.fallback&&(e="hash"),K||(e="abstract"),this.mode=e,e){case"history":this.history=new Tt(this,t.base);break;case"hash":this.history=new Pt(this,t.base,this.fallback);break;case"abstract":this.history=new Vt(this,t.base)}}match(t,e,n){return this.matcher.match(t,e,n)}get currentRoute(){return this.history&&this.history.current}init(t){if(this.apps.push(t),t.$once("hook:destroyed",()=>{const e=this.apps.indexOf(t);e>-1&&this.apps.splice(e,1),this.app===t&&(this.app=this.apps[0]||null),this.app||this.history.teardown()}),this.app)return;this.app=t;const e=this.history;if(e instanceof Tt||e instanceof Pt){const t=t=>{const n=e.current,r=this.options.scrollBehavior;pt&&r&&"fullPath"in t&&ot(this,t,n,!1)},n=n=>{e.setupListeners(),t(n)};e.transitionTo(e.getCurrentLocation(),n,n)}e.listen(t=>{this.apps.forEach(e=>{e._route=t})})}beforeEach(t){return Ht(this.beforeHooks,t)}beforeResolve(t){return Ht(this.resolveHooks,t)}afterEach(t){return Ht(this.afterHooks,t)}onReady(t,e){this.history.onReady(t,e)}onError(t){this.history.onError(t)}push(t,e,n){if(!e&&!n&&"undefined"!=typeof Promise)return new Promise((e,n)=>{this.history.push(t,e,n)});this.history.push(t,e,n)}replace(t,e,n){if(!e&&!n&&"undefined"!=typeof Promise)return new Promise((e,n)=>{this.history.replace(t,e,n)});this.history.replace(t,e,n)}go(t){this.history.go(t)}back(){this.go(-1)}forward(){this.go(1)}getMatchedComponents(t){const e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(t=>Object.keys(t.components).map(e=>t.components[e]))):[]}resolve(t,e,n){const r=V(t,e=e||this.history.current,n,this),o=this.match(r,e),i=o.redirectedFrom||o.fullPath;return{location:r,route:o,href:function(t,e,n){var r="hash"===n?"#"+e:e;return t?b(t+"/"+r):r}(this.history.base,i,this.mode),normalizedTo:r,resolved:o}}addRoutes(t){this.matcher.addRoutes(t),this.history.current!==d&&this.history.transitionTo(this.history.getCurrentLocation())}}function Ht(t,e){return t.push(e),()=>{const n=t.indexOf(e);n>-1&&t.splice(n,1)}}Bt.install=function t(n){if(t.installed&&D===n)return;t.installed=!0,D=n;const r=t=>void 0!==t,o=(t,e)=>{let n=t.$options._parentVnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};n.mixin({beforeCreate(){r(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),n.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,o(this,this)},destroyed(){o(this)}}),Object.defineProperty(n.prototype,"$router",{get(){return this._routerRoot._router}}),Object.defineProperty(n.prototype,"$route",{get(){return this._routerRoot._route}}),n.component("RouterView",e),n.component("RouterLink",N);const i=n.config.optionMergeStrategies;i.beforeRouteEnter=i.beforeRouteLeave=i.beforeRouteUpdate=i.created},Bt.version="3.4.5",Bt.isNavigationFailure=Rt,Bt.NavigationFailureType=mt,K&&window.Vue&&window.Vue.use(Bt);export default Bt; \ No newline at end of file +function t(t,e){for(const n in e)t[n]=e[n];return t}const e=/[!'()*]/g,n=t=>"%"+t.charCodeAt(0).toString(16),r=/%2C/g,o=t=>encodeURIComponent(t).replace(e,n).replace(r,",");function i(t){try{return decodeURIComponent(t)}catch(t){}return t}const s=t=>null==t||"object"==typeof t?t:String(t);function a(t){const e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(t=>{const n=t.replace(/\+/g," ").split("="),r=i(n.shift()),o=n.length>0?i(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 c(t){const e=t?Object.keys(t).map(e=>{const n=t[e];if(void 0===n)return"";if(null===n)return o(e);if(Array.isArray(n)){const t=[];return n.forEach(n=>{void 0!==n&&(null===n?t.push(o(e)):t.push(o(e)+"="+o(n)))}),t.join("&")}return o(e)+"="+o(n)}).filter(t=>t.length>0).join("&"):null;return e?`?${e}`:""}const u=/\/?$/;function h(t,e,n,r){const o=r&&r.options.stringifyQuery;let i=e.query||{};try{i=l(i)}catch(t){}const s={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:d(e,o),matched:t?f(t):[]};return n&&(s.redirectedFrom=d(n,o)),Object.freeze(s)}function l(t){if(Array.isArray(t))return t.map(l);if(t&&"object"==typeof t){const e={};for(const n in t)e[n]=l(t[n]);return e}return t}const p=h(null,{path:"/"});function f(t){const e=[];for(;t;)e.unshift(t),t=t.parent;return e}function d({path:t,query:e={},hash:n=""},r){return(t||"/")+(r||c)(e)+n}function y(t,e){return e===p?t===e:!!e&&(t.path&&e.path?t.path.replace(u,"")===e.path.replace(u,"")&&t.hash===e.hash&&m(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&m(t.query,e.query)&&m(t.params,e.params)))}function m(t={},e={}){if(!t||!e)return t===e;const n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(n=>{const r=t[n],o=e[n];return null==r||null==o?r===o:"object"==typeof r&&"object"==typeof o?m(r,o):String(r)===String(o)})}function g(t){for(let e=0;e{const n=p.instances[a];(e&&n!==t||!e&&n===t)&&(p.instances[a]=e)},(i.hook||(i.hook={})).prepatch=(t,e)=>{p.instances[a]=e.componentInstance},i.hook.init=t=>{t.data.keepAlive&&t.componentInstance&&t.componentInstance!==p.instances[a]&&(p.instances[a]=t.componentInstance),g(c)};const d=p.props&&p.props[a];return d&&(t(u[a],{route:c,configProps:d}),b(f,i,c,d)),s(f,i,r)}};function b(e,n,r,o){let i=n.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(r,o);if(i){i=n.props=t({},i);const r=n.attrs=n.attrs||{};for(const t in i)e.props&&t in e.props||(r[t]=i[t],delete i[t])}}function v(t,e,n){const r=t.charAt(0);if("/"===r)return t;if("?"===r||"#"===r)return e+t;const o=e.split("/");n&&o[o.length-1]||o.pop();const i=t.replace(/^\//,"").split("/");for(let t=0;t=0&&(e=t.slice(r),t=t.slice(0,r));const o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}(i.path||""),u=n&&n.path||"/",h=c.path?v(c.path,u,r||i.append):u,l=function(t,e={},n){const r=n||a;let o;try{o=r(t||"")}catch(t){o={}}for(const t in e){const n=e[t];o[t]=Array.isArray(n)?n.map(s):s(n)}return o}(c.query,i.query,o&&o.options.parseQuery);let p=i.hash||c.hash;return p&&"#"!==p.charAt(0)&&(p=`#${p}`),{_normalized:!0,path:h,query:l,hash:p}}const H=[String,Object],F=[String,Array],N=()=>{};var z={name:"RouterLink",props:{to:{type:H,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,ariaCurrentValue:{type:String,default:"page"},event:{type:F,default:"click"}},render(e){const n=this.$router,r=this.$route,{location:o,route:i,href:s}=n.resolve(this.to,r,this.append),a={},c=n.options.linkActiveClass,l=n.options.linkExactActiveClass,p=null==c?"router-link-active":c,f=null==l?"router-link-exact-active":l,d=null==this.activeClass?p:this.activeClass,m=null==this.exactActiveClass?f:this.exactActiveClass,g=i.redirectedFrom?h(null,B(i.redirectedFrom),null,n):i;a[m]=y(r,g),a[d]=this.exact?a[m]:function(t,e){return 0===t.path.replace(u,"/").indexOf(e.path.replace(u,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(const n in e)if(!(n in t))return!1;return!0}(t.query,e.query)}(r,g);const w=a[m]?this.ariaCurrentValue:null,b=t=>{D(t)&&(this.replace?n.replace(o,N):n.push(o,N))},v={click:D};Array.isArray(this.event)?this.event.forEach(t=>{v[t]=b}):v[this.event]=b;const x={class:a},k=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:s,route:i,navigate:b,isActive:a[d],isExactActive:a[m]});if(k){if(1===k.length)return k[0];if(k.length>1||!k.length)return 0===k.length?e():e("span",{},k)}if("a"===this.tag)x.on=v,x.attrs={href:s,"aria-current":w};else{const e=function t(e){if(e){let n;for(let r=0;r{!function t(e,n,r,o,i,s){const{path:a,name:c}=o;const u=o.pathToRegexpOptions||{};const h=function(t,e,n){n||(t=t.replace(/\/$/,""));return"/"===t[0]?t:null==e?t:x(`${e.path}/${t}`)}(a,i,u.strict);"boolean"==typeof o.caseSensitive&&(u.sensitive=o.caseSensitive);const l={path:h,regex:X(h,u),components:o.components||{default:o.component},instances:{},enteredCbs:{},name:c,parent:i,matchAs:s,redirect:o.redirect,beforeEnter:o.beforeEnter,meta:o.meta||{},props:null==o.props?{}:o.components?o.props:{default:o.props}};o.children&&o.children.forEach(o=>{const i=s?x(`${s}/${o.path}`):void 0;t(e,n,r,o,l,i)});n[l.path]||(e.push(l.path),n[l.path]=l);if(void 0!==o.alias){const s=Array.isArray(o.alias)?o.alias:[o.alias];for(let a=0;a!t.optional).map(t=>t.name);if("object"!=typeof c.params&&(c.params={}),i&&"object"==typeof i.params)for(const t in i.params)!(t in c.params)&&e.indexOf(t)>-1&&(c.params[t]=i.params[t]);return c.path=V(t.path,c.params),a(t,c,s)}if(c.path){c.params={};for(let t=0;t{window.removeEventListener("popstate",at)}}function it(t,e,n,r){if(!t.app)return;const o=t.options.scrollBehavior;o&&t.app.$nextTick(()=>{const i=function(){const t=et();if(t)return rt[t]}(),s=o.call(t,e,n,r?i:null);s&&("function"==typeof s.then?s.then(t=>{pt(t,i)}).catch(t=>{}):pt(s,i))})}function st(){const t=et();t&&(rt[t]={x:window.pageXOffset,y:window.pageYOffset})}function at(t){st(),t.state&&t.state.key&&nt(t.state.key)}function ct(t){return ht(t.x)||ht(t.y)}function ut(t){return{x:ht(t.x)?t.x:window.pageXOffset,y:ht(t.y)?t.y:window.pageYOffset}}function ht(t){return"number"==typeof t}const lt=/^#\d/;function pt(t,e){const n="object"==typeof t;if(n&&"string"==typeof t.selector){const n=lt.test(t.selector)?document.getElementById(t.selector.slice(1)):document.querySelector(t.selector);if(n){let o=t.offset&&"object"==typeof t.offset?t.offset:{};e=function(t,e){const n=document.documentElement.getBoundingClientRect(),r=t.getBoundingClientRect();return{x:r.left-n.left-e.x,y:r.top-n.top-e.y}}(n,o={x:ht((r=o).x)?r.x:0,y:ht(r.y)?r.y:0})}else ct(t)&&(e=ut(t))}else n&&ct(t)&&(e=ut(t));var r;e&&window.scrollTo(e.x,e.y)}const ft=J&&function(){const t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"function"==typeof window.history.pushState)}();function dt(e,n){st();const r=window.history;try{if(n){const n=t({},r.state);n.key=et(),r.replaceState(n,"",e)}else r.pushState({key:nt(Z())},"",e)}catch(t){window.location[n?"replace":"assign"](e)}}function yt(t){dt(t,!0)}function mt(t,e,n){const r=o=>{o>=t.length?n():t[o]?e(t[o],()=>{r(o+1)}):r(o+1)};r(0)}const gt={redirected:2,aborted:4,cancelled:8,duplicated:16};function wt(t,e){return vt(t,e,gt.redirected,`Redirected when going from "${t.fullPath}" to "${function(t){if("string"==typeof t)return t;if("path"in t)return t.path;const e={};return xt.forEach(n=>{n in t&&(e[n]=t[n])}),JSON.stringify(e,null,2)}(e)}" via a navigation guard.`)}function bt(t,e){return vt(t,e,gt.cancelled,`Navigation cancelled from "${t.fullPath}" to "${e.fullPath}" with a new navigation.`)}function vt(t,e,n,r){const o=new Error(r);return o._isRouter=!0,o.from=t,o.to=e,o.type=n,o}const xt=["params","query","hash"];function kt(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function Rt(t,e){return kt(t)&&t._isRouter&&(null==e||t.type===e)}function Et(t){return(e,n,r)=>{let o=!1,i=0,s=null;$t(t,(t,e,n,a)=>{if("function"==typeof t&&void 0===t.cid){o=!0,i++;const e=Ot(e=>{(function(t){return t.__esModule||At&&"Module"===t[Symbol.toStringTag]})(e)&&(e=e.default),t.resolved="function"==typeof e?e:K.extend(e),n.components[a]=e,--i<=0&&r()}),c=Ot(t=>{const e=`Failed to resolve async component ${a}: ${t}`;s||(s=kt(t)?t:new Error(e),r(s))});let u;try{u=t(e,c)}catch(t){c(t)}if(u)if("function"==typeof u.then)u.then(e,c);else{const t=u.component;t&&"function"==typeof t.then&&t.then(e,c)}}}),o||r()}}function $t(t,e){return Ct(t.map(t=>Object.keys(t.components).map(n=>e(t.components[n],t.instances[n],t,n))))}function Ct(t){return Array.prototype.concat.apply([],t)}const At="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function Ot(t){let e=!1;return function(...n){if(!e)return e=!0,t.apply(this,n)}}class St{constructor(t,e){this.router=t,this.base=function(t){if(!t)if(J){const e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";"/"!==t.charAt(0)&&(t="/"+t);return t.replace(/\/$/,"")}(e),this.current=p,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[],this.listeners=[]}listen(t){this.cb=t}onReady(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))}onError(t){this.errorCbs.push(t)}transitionTo(t,e,n){let r;try{r=this.router.match(t,this.current)}catch(t){throw this.errorCbs.forEach(e=>{e(t)}),t}const o=this.current;this.confirmTransition(r,()=>{this.updateRoute(r),e&&e(r),this.ensureURL(),this.router.afterHooks.forEach(t=>{t&&t(r,o)}),this.ready||(this.ready=!0,this.readyCbs.forEach(t=>{t(r)}))},t=>{n&&n(t),t&&!this.ready&&(Rt(t,gt.redirected)&&o===p||(this.ready=!0,this.readyErrorCbs.forEach(e=>{e(t)})))})}confirmTransition(t,e,n){const r=this.current;this.pending=t;const o=t=>{!Rt(t)&&kt(t)&&(this.errorCbs.length?this.errorCbs.forEach(e=>{e(t)}):console.error(t)),n&&n(t)},i=t.matched.length-1,s=r.matched.length-1;if(y(t,r)&&i===s&&t.matched[i]===r.matched[s])return this.ensureURL(),o(function(t,e){const n=vt(t,e,gt.duplicated,`Avoided redundant navigation to current location: "${t.fullPath}".`);return n.name="NavigationDuplicated",n}(r,t));const{updated:a,deactivated:c,activated:u}=function(t,e){let n;const r=Math.max(t.length,e.length);for(n=0;nt.beforeEnter),Et(u)),l=(e,n)=>{if(this.pending!==t)return o(bt(r,t));try{e(t,r,e=>{!1===e?(this.ensureURL(!0),o(function(t,e){return vt(t,e,gt.aborted,`Navigation aborted from "${t.fullPath}" to "${e.fullPath}" via a navigation guard.`)}(r,t))):kt(e)?(this.ensureURL(!0),o(e)):"string"==typeof e||"object"==typeof e&&("string"==typeof e.path||"string"==typeof e.name)?(o(wt(r,t)),"object"==typeof e&&e.replace?this.replace(e):this.push(e)):n(e)})}catch(t){o(t)}};mt(h,l,()=>{mt(function(t){return jt(t,"beforeRouteEnter",(t,e,n,r)=>(function(t,e,n){return function(r,o,i){return t(r,o,t=>{"function"==typeof t&&(e.enteredCbs[n]||(e.enteredCbs[n]=[]),e.enteredCbs[n].push(t)),i(t)})}})(t,n,r))}(u).concat(this.router.resolveHooks),l,()=>{if(this.pending!==t)return o(bt(r,t));this.pending=null,e(t),this.router.app&&this.router.app.$nextTick(()=>{g(t)})})})}updateRoute(t){this.current=t,this.cb&&this.cb(t)}setupListeners(){}teardown(){this.listeners.forEach(t=>{t()}),this.listeners=[],this.current=p,this.pending=null}}function jt(t,e,n,r){const o=$t(t,(t,r,o,i)=>{const s=function(t,e){"function"!=typeof t&&(t=K.extend(t));return t.options[e]}(t,e);if(s)return Array.isArray(s)?s.map(t=>n(t,r,o,i)):n(s,r,o,i)});return Ct(r?o.reverse():o)}function Lt(t,e){if(e)return function(){return t.apply(e,arguments)}}class Pt extends St{constructor(t,e){super(t,e),this._startLocation=Tt(this.base)}setupListeners(){if(this.listeners.length>0)return;const t=this.router,e=t.options.scrollBehavior,n=ft&&e;n&&this.listeners.push(ot());const r=()=>{const e=this.current,r=Tt(this.base);this.current===p&&r===this._startLocation||this.transitionTo(r,r=>{n&&it(t,r,e,!0)})};window.addEventListener("popstate",r),this.listeners.push(()=>{window.removeEventListener("popstate",r)})}go(t){window.history.go(t)}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{dt(x(this.base+t.fullPath)),it(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{yt(x(this.base+t.fullPath)),it(this.router,t,r,!1),e&&e(t)},n)}ensureURL(t){if(Tt(this.base)!==this.current.fullPath){const e=x(this.base+this.current.fullPath);t?dt(e):yt(e)}}getCurrentLocation(){return Tt(this.base)}}function Tt(t){let e=window.location.pathname;return t&&0===e.toLowerCase().indexOf(t.toLowerCase())&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}class _t extends St{constructor(t,e,n){super(t,e),n&&function(t){const e=Tt(t);if(!/^\/#/.test(e))return window.location.replace(x(t+"/#"+e)),!0}(this.base)||qt()}setupListeners(){if(this.listeners.length>0)return;const t=this.router.options.scrollBehavior,e=ft&&t;e&&this.listeners.push(ot());const n=()=>{const t=this.current;qt()&&this.transitionTo(Ut(),n=>{e&&it(this.router,n,t,!0),ft||Vt(n.fullPath)})},r=ft?"popstate":"hashchange";window.addEventListener(r,n),this.listeners.push(()=>{window.removeEventListener(r,n)})}push(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Mt(t.fullPath),it(this.router,t,r,!1),e&&e(t)},n)}replace(t,e,n){const{current:r}=this;this.transitionTo(t,t=>{Vt(t.fullPath),it(this.router,t,r,!1),e&&e(t)},n)}go(t){window.history.go(t)}ensureURL(t){const e=this.current.fullPath;Ut()!==e&&(t?Mt(e):Vt(e))}getCurrentLocation(){return Ut()}}function qt(){const t=Ut();return"/"===t.charAt(0)||(Vt("/"+t),!1)}function Ut(){let t=window.location.href;const e=t.indexOf("#");return e<0?"":t=t.slice(e+1)}function It(t){const e=window.location.href,n=e.indexOf("#");return`${n>=0?e.slice(0,n):e}#${t}`}function Mt(t){ft?dt(It(t)):window.location.hash=t}function Vt(t){ft?yt(It(t)):window.location.replace(It(t))}class Bt extends St{constructor(t,e){super(t,e),this.stack=[],this.index=-1}push(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index+1).concat(t),this.index++,e&&e(t)},n)}replace(t,e,n){this.transitionTo(t,t=>{this.stack=this.stack.slice(0,this.index).concat(t),e&&e(t)},n)}go(t){const e=this.index+t;if(e<0||e>=this.stack.length)return;const n=this.stack[e];this.confirmTransition(n,()=>{const t=this.current;this.index=e,this.updateRoute(n),this.router.afterHooks.forEach(e=>{e&&e(n,t)})},t=>{Rt(t,gt.duplicated)&&(this.index=e)})}getCurrentLocation(){const t=this.stack[this.stack.length-1];return t?t.fullPath:"/"}ensureURL(){}}class Ht{constructor(t={}){this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=Y(t.routes||[],this);let e=t.mode||"hash";switch(this.fallback="history"===e&&!ft&&!1!==t.fallback,this.fallback&&(e="hash"),J||(e="abstract"),this.mode=e,e){case"history":this.history=new Pt(this,t.base);break;case"hash":this.history=new _t(this,t.base,this.fallback);break;case"abstract":this.history=new Bt(this,t.base)}}match(t,e,n){return this.matcher.match(t,e,n)}get currentRoute(){return this.history&&this.history.current}init(t){if(this.apps.push(t),t.$once("hook:destroyed",()=>{const e=this.apps.indexOf(t);e>-1&&this.apps.splice(e,1),this.app===t&&(this.app=this.apps[0]||null),this.app||this.history.teardown()}),this.app)return;this.app=t;const e=this.history;if(e instanceof Pt||e instanceof _t){const t=t=>{const n=e.current,r=this.options.scrollBehavior;ft&&r&&"fullPath"in t&&it(this,t,n,!1)},n=n=>{e.setupListeners(),t(n)};e.transitionTo(e.getCurrentLocation(),n,n)}e.listen(t=>{this.apps.forEach(e=>{e._route=t})})}beforeEach(t){return Ft(this.beforeHooks,t)}beforeResolve(t){return Ft(this.resolveHooks,t)}afterEach(t){return Ft(this.afterHooks,t)}onReady(t,e){this.history.onReady(t,e)}onError(t){this.history.onError(t)}push(t,e,n){if(!e&&!n&&"undefined"!=typeof Promise)return new Promise((e,n)=>{this.history.push(t,e,n)});this.history.push(t,e,n)}replace(t,e,n){if(!e&&!n&&"undefined"!=typeof Promise)return new Promise((e,n)=>{this.history.replace(t,e,n)});this.history.replace(t,e,n)}go(t){this.history.go(t)}back(){this.go(-1)}forward(){this.go(1)}getMatchedComponents(t){const e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(t=>Object.keys(t.components).map(e=>t.components[e]))):[]}resolve(t,e,n){const r=B(t,e=e||this.history.current,n,this),o=this.match(r,e),i=o.redirectedFrom||o.fullPath;return{location:r,route:o,href:function(t,e,n){var r="hash"===n?"#"+e:e;return t?x(t+"/"+r):r}(this.history.base,i,this.mode),normalizedTo:r,resolved:o}}addRoutes(t){this.matcher.addRoutes(t),this.history.current!==p&&this.history.transitionTo(this.history.getCurrentLocation())}}function Ft(t,e){return t.push(e),()=>{const n=t.indexOf(e);n>-1&&t.splice(n,1)}}Ht.install=function t(e){if(t.installed&&K===e)return;t.installed=!0,K=e;const n=t=>void 0!==t,r=(t,e)=>{let r=t.$options._parentVnode;n(r)&&n(r=r.data)&&n(r=r.registerRouteInstance)&&r(t,e)};e.mixin({beforeCreate(){n(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),e.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,r(this,this)},destroyed(){r(this)}}),Object.defineProperty(e.prototype,"$router",{get(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get(){return this._routerRoot._route}}),e.component("RouterView",w),e.component("RouterLink",z);const o=e.config.optionMergeStrategies;o.beforeRouteEnter=o.beforeRouteLeave=o.beforeRouteUpdate=o.created},Ht.version="3.4.6",Ht.isNavigationFailure=Rt,Ht.NavigationFailureType=gt,J&&window.Vue&&window.Vue.use(Ht);export default Ht; \ No newline at end of file diff --git a/dist/vue-router.esm.js b/dist/vue-router.esm.js index e723acb72..137f8550e 100644 --- a/dist/vue-router.esm.js +++ b/dist/vue-router.esm.js @@ -1,5 +1,5 @@ /*! - * vue-router v3.4.5 + * vue-router v3.4.6 * (c) 2020 Evan You * @license MIT */ @@ -24,158 +24,6 @@ function extend (a, b) { return a } -var View = { - name: 'RouterView', - functional: true, - props: { - name: { - type: String, - default: 'default' - } - }, - render: function render (_, ref) { - var props = ref.props; - var children = ref.children; - var parent = ref.parent; - var data = ref.data; - - // used by devtools to display a router-view badge - data.routerView = true; - - // directly use parent context's createElement() function - // so that components rendered by router-view can resolve named slots - var h = parent.$createElement; - var name = props.name; - var route = parent.$route; - var cache = parent._routerViewCache || (parent._routerViewCache = {}); - - // determine current view depth, also check to see if the tree - // has been toggled inactive but kept-alive. - var depth = 0; - var inactive = false; - while (parent && parent._routerRoot !== parent) { - var vnodeData = parent.$vnode ? parent.$vnode.data : {}; - if (vnodeData.routerView) { - depth++; - } - if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { - inactive = true; - } - parent = parent.$parent; - } - data.routerViewDepth = depth; - - // render previous view if the tree is inactive and kept-alive - if (inactive) { - var cachedData = cache[name]; - var cachedComponent = cachedData && cachedData.component; - if (cachedComponent) { - // #2301 - // pass props - if (cachedData.configProps) { - fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); - } - return h(cachedComponent, data, children) - } else { - // render previous empty view - return h() - } - } - - var matched = route.matched[depth]; - var component = matched && matched.components[name]; - - // render empty node if no matched route or no config component - if (!matched || !component) { - cache[name] = null; - return h() - } - - // cache component - cache[name] = { component: component }; - - // attach instance registration hook - // this will be called in the instance's injected lifecycle hooks - data.registerRouteInstance = function (vm, val) { - // val could be undefined for unregistration - var current = matched.instances[name]; - if ( - (val && current !== vm) || - (!val && current === vm) - ) { - matched.instances[name] = val; - } - } - - // also register instance in prepatch hook - // in case the same component instance is reused across different routes - ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { - matched.instances[name] = vnode.componentInstance; - }; - - // register instance in init hook - // in case kept-alive component be actived when routes changed - data.hook.init = function (vnode) { - if (vnode.data.keepAlive && - vnode.componentInstance && - vnode.componentInstance !== matched.instances[name] - ) { - matched.instances[name] = vnode.componentInstance; - } - }; - - var configProps = matched.props && matched.props[name]; - // save route and configProps in cache - if (configProps) { - extend(cache[name], { - route: route, - configProps: configProps - }); - fillPropsinData(component, data, route, configProps); - } - - return h(component, data, children) - } -}; - -function fillPropsinData (component, data, route, configProps) { - // resolve props - var propsToPass = data.props = resolveProps(route, configProps); - if (propsToPass) { - // clone to prevent mutation - propsToPass = data.props = extend({}, propsToPass); - // pass non-declared props as attrs - var attrs = data.attrs = data.attrs || {}; - for (var key in propsToPass) { - if (!component.props || !(key in component.props)) { - attrs[key] = propsToPass[key]; - delete propsToPass[key]; - } - } - } -} - -function resolveProps (route, config) { - switch (typeof config) { - case 'undefined': - return - case 'object': - return config - case 'function': - return config(route) - case 'boolean': - return config ? route.params : undefined - default: - if (process.env.NODE_ENV !== 'production') { - warn( - false, - "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + - "expecting an object, function or boolean." - ); - } - } -} - /* */ var encodeReserveRE = /[!'()*]/g; @@ -189,7 +37,16 @@ var encode = function (str) { return encodeURIComponent(str) .replace(encodeReserveRE, encodeReserveReplacer) .replace(commaRE, ','); }; -var decode = decodeURIComponent; +function decode (str) { + try { + return decodeURIComponent(str) + } catch (err) { + if (process.env.NODE_ENV !== 'production') { + warn(false, ("Error decoding \"" + str + "\". Leaving it intact.")); + } + } + return str +} function resolveQuery ( query, @@ -419,6 +276,178 @@ function queryIncludes (current, target) { return true } +function handleRouteEntered (route) { + for (var i = 0; i < route.matched.length; i++) { + var record = route.matched[i]; + for (var name in record.instances) { + var instance = record.instances[name]; + var cbs = record.enteredCbs[name]; + if (!instance || !cbs) { continue } + delete record.enteredCbs[name]; + for (var i$1 = 0; i$1 < cbs.length; i$1++) { + if (!instance._isBeingDestroyed) { cbs[i$1](instance); } + } + } + } +} + +var View = { + name: 'RouterView', + functional: true, + props: { + name: { + type: String, + default: 'default' + } + }, + render: function render (_, ref) { + var props = ref.props; + var children = ref.children; + var parent = ref.parent; + var data = ref.data; + + // used by devtools to display a router-view badge + data.routerView = true; + + // directly use parent context's createElement() function + // so that components rendered by router-view can resolve named slots + var h = parent.$createElement; + var name = props.name; + var route = parent.$route; + var cache = parent._routerViewCache || (parent._routerViewCache = {}); + + // determine current view depth, also check to see if the tree + // has been toggled inactive but kept-alive. + var depth = 0; + var inactive = false; + while (parent && parent._routerRoot !== parent) { + var vnodeData = parent.$vnode ? parent.$vnode.data : {}; + if (vnodeData.routerView) { + depth++; + } + if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { + inactive = true; + } + parent = parent.$parent; + } + data.routerViewDepth = depth; + + // render previous view if the tree is inactive and kept-alive + if (inactive) { + var cachedData = cache[name]; + var cachedComponent = cachedData && cachedData.component; + if (cachedComponent) { + // #2301 + // pass props + if (cachedData.configProps) { + fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); + } + return h(cachedComponent, data, children) + } else { + // render previous empty view + return h() + } + } + + var matched = route.matched[depth]; + var component = matched && matched.components[name]; + + // render empty node if no matched route or no config component + if (!matched || !component) { + cache[name] = null; + return h() + } + + // cache component + cache[name] = { component: component }; + + // attach instance registration hook + // this will be called in the instance's injected lifecycle hooks + data.registerRouteInstance = function (vm, val) { + // val could be undefined for unregistration + var current = matched.instances[name]; + if ( + (val && current !== vm) || + (!val && current === vm) + ) { + matched.instances[name] = val; + } + } + + // also register instance in prepatch hook + // in case the same component instance is reused across different routes + ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { + matched.instances[name] = vnode.componentInstance; + }; + + // register instance in init hook + // in case kept-alive component be actived when routes changed + data.hook.init = function (vnode) { + if (vnode.data.keepAlive && + vnode.componentInstance && + vnode.componentInstance !== matched.instances[name] + ) { + matched.instances[name] = vnode.componentInstance; + } + + // if the route transition has already been confirmed then we weren't + // able to call the cbs during confirmation as the component was not + // registered yet, so we call it here. + handleRouteEntered(route); + }; + + var configProps = matched.props && matched.props[name]; + // save route and configProps in cache + if (configProps) { + extend(cache[name], { + route: route, + configProps: configProps + }); + fillPropsinData(component, data, route, configProps); + } + + return h(component, data, children) + } +}; + +function fillPropsinData (component, data, route, configProps) { + // resolve props + var propsToPass = data.props = resolveProps(route, configProps); + if (propsToPass) { + // clone to prevent mutation + propsToPass = data.props = extend({}, propsToPass); + // pass non-declared props as attrs + var attrs = data.attrs = data.attrs || {}; + for (var key in propsToPass) { + if (!component.props || !(key in component.props)) { + attrs[key] = propsToPass[key]; + delete propsToPass[key]; + } + } + } +} + +function resolveProps (route, config) { + switch (typeof config) { + case 'undefined': + return + case 'object': + return config + case 'function': + return config(route) + case 'boolean': + return config ? route.params : undefined + default: + if (process.env.NODE_ENV !== 'production') { + warn( + false, + "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + + "expecting an object, function or boolean." + ); + } + } +} + /* */ function resolvePath ( @@ -1349,6 +1378,7 @@ function addRouteRecord ( regex: compileRouteRegex(normalizedPath, pathToRegexpOptions), components: route.components || { default: route.component }, instances: {}, + enteredCbs: {}, name: name, parent: parent, matchAs: matchAs, @@ -1638,7 +1668,14 @@ function matchRoute ( path, params ) { - var m = path.match(regex); + var m; + try { + m = decodeURI(path).match(regex); + } catch (err) { + if (process.env.NODE_ENV !== 'production') { + warn(false, ("Error decoding \"" + path + "\". Leaving it intact.")); + } + } if (!m) { return false @@ -1648,10 +1685,9 @@ function matchRoute ( for (var i = 1, len = m.length; i < len; ++i) { var key = regex.keys[i - 1]; - var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]; if (key) { // Fix #1994: using * with props: true generates a param named 0 - params[key.name || 'pathMatch'] = val; + params[key.name || 'pathMatch'] = m[i]; } } @@ -2279,11 +2315,9 @@ History.prototype.confirmTransition = function confirmTransition (route, onCompl }; runQueue(queue, iterator, function () { - var postEnterCbs = []; - var isValid = function () { return this$1.current === route; }; // wait until async components are resolved before // extracting in-component enter guards - var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid); + var enterGuards = extractEnterGuards(activated); var queue = enterGuards.concat(this$1.router.resolveHooks); runQueue(queue, iterator, function () { if (this$1.pending !== route) { @@ -2293,9 +2327,7 @@ History.prototype.confirmTransition = function confirmTransition (route, onCompl onComplete(route); if (this$1.router.app) { this$1.router.app.$nextTick(function () { - postEnterCbs.forEach(function (cb) { - cb(); - }); + handleRouteEntered(route); }); } }); @@ -2408,15 +2440,13 @@ function bindGuard (guard, instance) { } function extractEnterGuards ( - activated, - cbs, - isValid + activated ) { return extractGuards( activated, 'beforeRouteEnter', function (guard, _, match, key) { - return bindEnterGuard(guard, match, key, cbs, isValid) + return bindEnterGuard(guard, match, key) } ) } @@ -2424,45 +2454,21 @@ function extractEnterGuards ( function bindEnterGuard ( guard, match, - key, - cbs, - isValid + key ) { return function routeEnterGuard (to, from, next) { return guard(to, from, function (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); - }); + if (!match.enteredCbs[key]) { + match.enteredCbs[key] = []; + } + match.enteredCbs[key].push(cb); } next(cb); }) } } -function poll ( - cb, // somehow flow cannot infer this is a function - instances, - key, - isValid -) { - if ( - instances[key] && - !instances[key]._isBeingDestroyed // do not reuse being destroyed instance - ) { - cb(instances[key]); - } else if (isValid()) { - setTimeout(function () { - poll(cb, instances, key, isValid); - }, 16); - } -} - /* */ var HTML5History = /*@__PURE__*/(function (History) { @@ -2556,7 +2562,7 @@ var HTML5History = /*@__PURE__*/(function (History) { }(History)); function getLocation (base) { - var path = decodeURI(window.location.pathname); + var path = window.location.pathname; if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) { path = path.slice(base.length); } @@ -2696,18 +2702,6 @@ function getHash () { if (index < 0) { return '' } href = href.slice(index + 1); - // decode the hash but not the search or hash - // as search(query) is already decoded - // https://github.com/vuejs/vue-router/issues/2708 - var searchIndex = href.indexOf('?'); - if (searchIndex < 0) { - var hashIndex = href.indexOf('#'); - if (hashIndex > -1) { - href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); - } else { href = decodeURI(href); } - } else { - href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); - } return href } @@ -3048,7 +3042,7 @@ function createHref (base, fullPath, mode) { } VueRouter.install = install; -VueRouter.version = '3.4.5'; +VueRouter.version = '3.4.6'; VueRouter.isNavigationFailure = isNavigationFailure; VueRouter.NavigationFailureType = NavigationFailureType; diff --git a/dist/vue-router.js b/dist/vue-router.js index 320cf5a19..7f6726a11 100644 --- a/dist/vue-router.js +++ b/dist/vue-router.js @@ -1,5 +1,5 @@ /*! - * vue-router v3.4.5 + * vue-router v3.4.6 * (c) 2020 Evan You * @license MIT */ @@ -30,158 +30,6 @@ return a } - var View = { - name: 'RouterView', - functional: true, - props: { - name: { - type: String, - default: 'default' - } - }, - render: function render (_, ref) { - var props = ref.props; - var children = ref.children; - var parent = ref.parent; - var data = ref.data; - - // used by devtools to display a router-view badge - data.routerView = true; - - // directly use parent context's createElement() function - // so that components rendered by router-view can resolve named slots - var h = parent.$createElement; - var name = props.name; - var route = parent.$route; - var cache = parent._routerViewCache || (parent._routerViewCache = {}); - - // determine current view depth, also check to see if the tree - // has been toggled inactive but kept-alive. - var depth = 0; - var inactive = false; - while (parent && parent._routerRoot !== parent) { - var vnodeData = parent.$vnode ? parent.$vnode.data : {}; - if (vnodeData.routerView) { - depth++; - } - if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { - inactive = true; - } - parent = parent.$parent; - } - data.routerViewDepth = depth; - - // render previous view if the tree is inactive and kept-alive - if (inactive) { - var cachedData = cache[name]; - var cachedComponent = cachedData && cachedData.component; - if (cachedComponent) { - // #2301 - // pass props - if (cachedData.configProps) { - fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); - } - return h(cachedComponent, data, children) - } else { - // render previous empty view - return h() - } - } - - var matched = route.matched[depth]; - var component = matched && matched.components[name]; - - // render empty node if no matched route or no config component - if (!matched || !component) { - cache[name] = null; - return h() - } - - // cache component - cache[name] = { component: component }; - - // attach instance registration hook - // this will be called in the instance's injected lifecycle hooks - data.registerRouteInstance = function (vm, val) { - // val could be undefined for unregistration - var current = matched.instances[name]; - if ( - (val && current !== vm) || - (!val && current === vm) - ) { - matched.instances[name] = val; - } - } - - // also register instance in prepatch hook - // in case the same component instance is reused across different routes - ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { - matched.instances[name] = vnode.componentInstance; - }; - - // register instance in init hook - // in case kept-alive component be actived when routes changed - data.hook.init = function (vnode) { - if (vnode.data.keepAlive && - vnode.componentInstance && - vnode.componentInstance !== matched.instances[name] - ) { - matched.instances[name] = vnode.componentInstance; - } - }; - - var configProps = matched.props && matched.props[name]; - // save route and configProps in cache - if (configProps) { - extend(cache[name], { - route: route, - configProps: configProps - }); - fillPropsinData(component, data, route, configProps); - } - - return h(component, data, children) - } - }; - - function fillPropsinData (component, data, route, configProps) { - // resolve props - var propsToPass = data.props = resolveProps(route, configProps); - if (propsToPass) { - // clone to prevent mutation - propsToPass = data.props = extend({}, propsToPass); - // pass non-declared props as attrs - var attrs = data.attrs = data.attrs || {}; - for (var key in propsToPass) { - if (!component.props || !(key in component.props)) { - attrs[key] = propsToPass[key]; - delete propsToPass[key]; - } - } - } - } - - function resolveProps (route, config) { - switch (typeof config) { - case 'undefined': - return - case 'object': - return config - case 'function': - return config(route) - case 'boolean': - return config ? route.params : undefined - default: - { - warn( - false, - "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + - "expecting an object, function or boolean." - ); - } - } - } - /* */ var encodeReserveRE = /[!'()*]/g; @@ -195,7 +43,16 @@ .replace(encodeReserveRE, encodeReserveReplacer) .replace(commaRE, ','); }; - var decode = decodeURIComponent; + function decode (str) { + try { + return decodeURIComponent(str) + } catch (err) { + { + warn(false, ("Error decoding \"" + str + "\". Leaving it intact.")); + } + } + return str + } function resolveQuery ( query, @@ -425,6 +282,178 @@ return true } + function handleRouteEntered (route) { + for (var i = 0; i < route.matched.length; i++) { + var record = route.matched[i]; + for (var name in record.instances) { + var instance = record.instances[name]; + var cbs = record.enteredCbs[name]; + if (!instance || !cbs) { continue } + delete record.enteredCbs[name]; + for (var i$1 = 0; i$1 < cbs.length; i$1++) { + if (!instance._isBeingDestroyed) { cbs[i$1](instance); } + } + } + } + } + + var View = { + name: 'RouterView', + functional: true, + props: { + name: { + type: String, + default: 'default' + } + }, + render: function render (_, ref) { + var props = ref.props; + var children = ref.children; + var parent = ref.parent; + var data = ref.data; + + // used by devtools to display a router-view badge + data.routerView = true; + + // directly use parent context's createElement() function + // so that components rendered by router-view can resolve named slots + var h = parent.$createElement; + var name = props.name; + var route = parent.$route; + var cache = parent._routerViewCache || (parent._routerViewCache = {}); + + // determine current view depth, also check to see if the tree + // has been toggled inactive but kept-alive. + var depth = 0; + var inactive = false; + while (parent && parent._routerRoot !== parent) { + var vnodeData = parent.$vnode ? parent.$vnode.data : {}; + if (vnodeData.routerView) { + depth++; + } + if (vnodeData.keepAlive && parent._directInactive && parent._inactive) { + inactive = true; + } + parent = parent.$parent; + } + data.routerViewDepth = depth; + + // render previous view if the tree is inactive and kept-alive + if (inactive) { + var cachedData = cache[name]; + var cachedComponent = cachedData && cachedData.component; + if (cachedComponent) { + // #2301 + // pass props + if (cachedData.configProps) { + fillPropsinData(cachedComponent, data, cachedData.route, cachedData.configProps); + } + return h(cachedComponent, data, children) + } else { + // render previous empty view + return h() + } + } + + var matched = route.matched[depth]; + var component = matched && matched.components[name]; + + // render empty node if no matched route or no config component + if (!matched || !component) { + cache[name] = null; + return h() + } + + // cache component + cache[name] = { component: component }; + + // attach instance registration hook + // this will be called in the instance's injected lifecycle hooks + data.registerRouteInstance = function (vm, val) { + // val could be undefined for unregistration + var current = matched.instances[name]; + if ( + (val && current !== vm) || + (!val && current === vm) + ) { + matched.instances[name] = val; + } + } + + // also register instance in prepatch hook + // in case the same component instance is reused across different routes + ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { + matched.instances[name] = vnode.componentInstance; + }; + + // register instance in init hook + // in case kept-alive component be actived when routes changed + data.hook.init = function (vnode) { + if (vnode.data.keepAlive && + vnode.componentInstance && + vnode.componentInstance !== matched.instances[name] + ) { + matched.instances[name] = vnode.componentInstance; + } + + // if the route transition has already been confirmed then we weren't + // able to call the cbs during confirmation as the component was not + // registered yet, so we call it here. + handleRouteEntered(route); + }; + + var configProps = matched.props && matched.props[name]; + // save route and configProps in cache + if (configProps) { + extend(cache[name], { + route: route, + configProps: configProps + }); + fillPropsinData(component, data, route, configProps); + } + + return h(component, data, children) + } + }; + + function fillPropsinData (component, data, route, configProps) { + // resolve props + var propsToPass = data.props = resolveProps(route, configProps); + if (propsToPass) { + // clone to prevent mutation + propsToPass = data.props = extend({}, propsToPass); + // pass non-declared props as attrs + var attrs = data.attrs = data.attrs || {}; + for (var key in propsToPass) { + if (!component.props || !(key in component.props)) { + attrs[key] = propsToPass[key]; + delete propsToPass[key]; + } + } + } + } + + function resolveProps (route, config) { + switch (typeof config) { + case 'undefined': + return + case 'object': + return config + case 'function': + return config(route) + case 'boolean': + return config ? route.params : undefined + default: + { + warn( + false, + "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + + "expecting an object, function or boolean." + ); + } + } + } + /* */ function resolvePath ( @@ -1355,6 +1384,7 @@ regex: compileRouteRegex(normalizedPath, pathToRegexpOptions), components: route.components || { default: route.component }, instances: {}, + enteredCbs: {}, name: name, parent: parent, matchAs: matchAs, @@ -1644,7 +1674,14 @@ path, params ) { - var m = path.match(regex); + var m; + try { + m = decodeURI(path).match(regex); + } catch (err) { + { + warn(false, ("Error decoding \"" + path + "\". Leaving it intact.")); + } + } if (!m) { return false @@ -1654,10 +1691,9 @@ for (var i = 1, len = m.length; i < len; ++i) { var key = regex.keys[i - 1]; - var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]; if (key) { // Fix #1994: using * with props: true generates a param named 0 - params[key.name || 'pathMatch'] = val; + params[key.name || 'pathMatch'] = m[i]; } } @@ -2285,11 +2321,9 @@ }; runQueue(queue, iterator, function () { - var postEnterCbs = []; - var isValid = function () { return this$1.current === route; }; // wait until async components are resolved before // extracting in-component enter guards - var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid); + var enterGuards = extractEnterGuards(activated); var queue = enterGuards.concat(this$1.router.resolveHooks); runQueue(queue, iterator, function () { if (this$1.pending !== route) { @@ -2299,9 +2333,7 @@ onComplete(route); if (this$1.router.app) { this$1.router.app.$nextTick(function () { - postEnterCbs.forEach(function (cb) { - cb(); - }); + handleRouteEntered(route); }); } }); @@ -2414,15 +2446,13 @@ } function extractEnterGuards ( - activated, - cbs, - isValid + activated ) { return extractGuards( activated, 'beforeRouteEnter', function (guard, _, match, key) { - return bindEnterGuard(guard, match, key, cbs, isValid) + return bindEnterGuard(guard, match, key) } ) } @@ -2430,45 +2460,21 @@ function bindEnterGuard ( guard, match, - key, - cbs, - isValid + key ) { return function routeEnterGuard (to, from, next) { return guard(to, from, function (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); - }); + if (!match.enteredCbs[key]) { + match.enteredCbs[key] = []; + } + match.enteredCbs[key].push(cb); } next(cb); }) } } - function poll ( - cb, // somehow flow cannot infer this is a function - instances, - key, - isValid - ) { - if ( - instances[key] && - !instances[key]._isBeingDestroyed // do not reuse being destroyed instance - ) { - cb(instances[key]); - } else if (isValid()) { - setTimeout(function () { - poll(cb, instances, key, isValid); - }, 16); - } - } - /* */ var HTML5History = /*@__PURE__*/(function (History) { @@ -2562,7 +2568,7 @@ }(History)); function getLocation (base) { - var path = decodeURI(window.location.pathname); + var path = window.location.pathname; if (base && path.toLowerCase().indexOf(base.toLowerCase()) === 0) { path = path.slice(base.length); } @@ -2702,18 +2708,6 @@ if (index < 0) { return '' } href = href.slice(index + 1); - // decode the hash but not the search or hash - // as search(query) is already decoded - // https://github.com/vuejs/vue-router/issues/2708 - var searchIndex = href.indexOf('?'); - if (searchIndex < 0) { - var hashIndex = href.indexOf('#'); - if (hashIndex > -1) { - href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); - } else { href = decodeURI(href); } - } else { - href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); - } return href } @@ -3054,7 +3048,7 @@ } VueRouter.install = install; - VueRouter.version = '3.4.5'; + VueRouter.version = '3.4.6'; VueRouter.isNavigationFailure = isNavigationFailure; VueRouter.NavigationFailureType = NavigationFailureType; diff --git a/dist/vue-router.min.js b/dist/vue-router.min.js index 26941a06a..325f4d025 100644 --- a/dist/vue-router.min.js +++ b/dist/vue-router.min.js @@ -1,6 +1,6 @@ /*! - * vue-router v3.4.5 + * vue-router v3.4.6 * (c) 2020 Evan You * @license MIT */ -var t,e;t=this,e=function(){"use strict";function t(t,e){for(var r in e)t[r]=e[r];return t}var e={name:"RouterView",functional:!0,props:{name:{type:String,default:"default"}},render:function(e,n){var o=n.props,i=n.children,a=n.parent,u=n.data;u.routerView=!0;for(var s=a.$createElement,c=o.name,p=a.$route,f=a._routerViewCache||(a._routerViewCache={}),h=0,l=!1;a&&a._routerRoot!==a;){var d=a.$vnode?a.$vnode.data:{};d.routerView&&h++,d.keepAlive&&a._directInactive&&a._inactive&&(l=!0),a=a.$parent}if(u.routerViewDepth=h,l){var v=f[c],y=v&&v.component;return y?(v.configProps&&r(y,u,v.route,v.configProps),s(y,u,i)):s()}var m=p.matched[h],g=m&&m.components[c];if(!m||!g)return f[c]=null,s();f[c]={component:g},u.registerRouteInstance=function(t,e){var r=m.instances[c];(e&&r!==t||!e&&r===t)&&(m.instances[c]=e)},(u.hook||(u.hook={})).prepatch=function(t,e){m.instances[c]=e.componentInstance},u.hook.init=function(t){t.data.keepAlive&&t.componentInstance&&t.componentInstance!==m.instances[c]&&(m.instances[c]=t.componentInstance)};var w=m.props&&m.props[c];return w&&(t(f[c],{route:p,configProps:w}),r(g,u,p,w)),s(g,u,i)}};function r(e,r,n,o){var i=r.props=function(t,e){switch(typeof e){case"undefined":return;case"object":return e;case"function":return e(t);case"boolean":return e?t.params:void 0}}(n,o);if(i){i=r.props=t({},i);var a=r.attrs=r.attrs||{};for(var u in i)e.props&&u in e.props||(a[u]=i[u],delete i[u])}}var n=/[!'()*]/g,o=function(t){return"%"+t.charCodeAt(0).toString(16)},i=/%2C/g,a=function(t){return encodeURIComponent(t).replace(n,o).replace(i,",")},u=decodeURIComponent,s=function(t){return null==t||"object"==typeof t?t:String(t)};function c(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var r=t.replace(/\+/g," ").split("="),n=u(r.shift()),o=r.length>0?u(r.join("=")):null;void 0===e[n]?e[n]=o:Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]}),e):e}function p(t){var e=t?Object.keys(t).map(function(e){var r=t[e];if(void 0===r)return"";if(null===r)return a(e);if(Array.isArray(r)){var n=[];return r.forEach(function(t){void 0!==t&&(null===t?n.push(a(e)):n.push(a(e)+"="+a(t)))}),n.join("&")}return a(e)+"="+a(r)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}var f=/\/?$/;function h(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=l(i)}catch(t){}var a={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:y(e,o),matched:t?v(t):[]};return r&&(a.redirectedFrom=y(r,o)),Object.freeze(a)}function l(t){if(Array.isArray(t))return t.map(l);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=l(t[r]);return e}return t}var d=h(null,{path:"/"});function v(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function y(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;return void 0===o&&(o=""),(r||"/")+(e||p)(n)+o}function m(t,e){return e===d?t===e:!!e&&(t.path&&e.path?t.path.replace(f,"")===e.path.replace(f,"")&&t.hash===e.hash&&g(t.query,e.query):!(!t.name||!e.name)&&t.name===e.name&&t.hash===e.hash&&g(t.query,e.query)&&g(t.params,e.params))}function g(t,e){if(void 0===t&&(t={}),void 0===e&&(e={}),!t||!e)return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(r){var n=t[r],o=e[r];return null==n||null==o?n===o:"object"==typeof n&&"object"==typeof o?g(n,o):String(n)===String(o)})}function w(t,e,r){var n=t.charAt(0);if("/"===n)return t;if("?"===n||"#"===n)return e+t;var o=e.split("/");r&&o[o.length-1]||o.pop();for(var i=t.replace(/^\//,"").split("/"),a=0;a=0&&(e=t.slice(n),t=t.slice(0,n));var o=t.indexOf("?");return o>=0&&(r=t.slice(o+1),t=t.slice(0,o)),{path:t,query:r,hash:e}}(i.path||""),h=r&&r.path||"/",l=f.path?w(f.path,h,n||i.append):h,d=function(t,e,r){void 0===e&&(e={});var n,o=r||c;try{n=o(t||"")}catch(t){n={}}for(var i in e){var a=e[i];n[i]=Array.isArray(a)?a.map(s):s(a)}return n}(f.query,i.query,o&&o.options.parseQuery),v=i.hash||f.hash;return v&&"#"!==v.charAt(0)&&(v="#"+v),{_normalized:!0,path:l,query:d,hash:v}}var B,H=[String,Object],F=[String,Array],N=function(){},z={name:"RouterLink",props:{to:{type:H,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,ariaCurrentValue:{type:String,default:"page"},event:{type:F,default:"click"}},render:function(e){var r=this,n=this.$router,o=this.$route,i=n.resolve(this.to,o,this.append),a=i.location,u=i.route,s=i.href,c={},p=n.options.linkActiveClass,l=n.options.linkExactActiveClass,d=null==p?"router-link-active":p,v=null==l?"router-link-exact-active":l,y=null==this.activeClass?d:this.activeClass,g=null==this.exactActiveClass?v:this.exactActiveClass,w=u.redirectedFrom?h(null,V(u.redirectedFrom),null,n):u;c[g]=m(o,w),c[y]=this.exact?c[g]:function(t,e){return 0===t.path.replace(f,"/").indexOf(e.path.replace(f,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(var r in e)if(!(r in t))return!1;return!0}(t.query,e.query)}(o,w);var b=c[g]?this.ariaCurrentValue:null,x=function(t){D(t)&&(r.replace?n.replace(a,N):n.push(a,N))},R={click:D};Array.isArray(this.event)?this.event.forEach(function(t){R[t]=x}):R[this.event]=x;var k={class:c},E=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:s,route:u,navigate:x,isActive:c[y],isExactActive:c[g]});if(E){if(1===E.length)return E[0];if(E.length>1||!E.length)return 0===E.length?e():e("span",{},E)}if("a"===this.tag)k.on=R,k.attrs={href:s,"aria-current":b};else{var A=function t(e){if(e)for(var r,n=0;n-1&&(u.params[h]=r.params[h]);return u.path=M(p.path,u.params),s(p,u,a)}if(u.path){u.params={};for(var l=0;l=t.length?r():t[o]?e(t[o],function(){n(o+1)}):n(o+1)};n(0)}var mt={redirected:2,aborted:4,cancelled:8,duplicated:16};function gt(t,e){return bt(t,e,mt.redirected,'Redirected when going from "'+t.fullPath+'" to "'+function(t){if("string"==typeof t)return t;if("path"in t)return t.path;var e={};return xt.forEach(function(r){r in t&&(e[r]=t[r])}),JSON.stringify(e,null,2)}(e)+'" via a navigation guard.')}function wt(t,e){return bt(t,e,mt.cancelled,'Navigation cancelled from "'+t.fullPath+'" to "'+e.fullPath+'" with a new navigation.')}function bt(t,e,r,n){var o=new Error(n);return o._isRouter=!0,o.from=t,o.to=e,o.type=r,o}var xt=["params","query","hash"];function Rt(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function kt(t,e){return Rt(t)&&t._isRouter&&(null==e||t.type===e)}function Et(t){return function(e,r,n){var o=!1,i=0,a=null;At(t,function(t,e,r,u){if("function"==typeof t&&void 0===t.cid){o=!0,i++;var s,c=_t(function(e){var o;((o=e).__esModule||Ct&&"Module"===o[Symbol.toStringTag])&&(e=e.default),t.resolved="function"==typeof e?e:B.extend(e),r.components[u]=e,--i<=0&&n()}),p=_t(function(t){var e="Failed to resolve async component "+u+": "+t;a||(a=Rt(t)?t:new Error(e),n(a))});try{s=t(c,p)}catch(t){p(t)}if(s)if("function"==typeof s.then)s.then(c,p);else{var f=s.component;f&&"function"==typeof f.then&&f.then(c,p)}}}),o||n()}}function At(t,e){return Ot(t.map(function(t){return Object.keys(t.components).map(function(r){return e(t.components[r],t.instances[r],t,r)})}))}function Ot(t){return Array.prototype.concat.apply([],t)}var Ct="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function _t(t){var e=!1;return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(!e)return e=!0,t.apply(this,r)}}var jt=function(t,e){this.router=t,this.base=function(t){if(!t)if(K){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}(e),this.current=d,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[],this.listeners=[]};function St(t,e,r,n){var o=At(t,function(t,n,o,i){var a=function(t,e){return"function"!=typeof t&&(t=B.extend(t)),t.options[e]}(t,e);if(a)return Array.isArray(a)?a.map(function(t){return r(t,n,o,i)}):r(a,n,o,i)});return Ot(n?o.reverse():o)}function $t(t,e){if(e)return function(){return t.apply(e,arguments)}}jt.prototype.listen=function(t){this.cb=t},jt.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},jt.prototype.onError=function(t){this.errorCbs.push(t)},jt.prototype.transitionTo=function(t,e,r){var n,o=this;try{n=this.router.match(t,this.current)}catch(t){throw this.errorCbs.forEach(function(e){e(t)}),t}var i=this.current;this.confirmTransition(n,function(){o.updateRoute(n),e&&e(n),o.ensureURL(),o.router.afterHooks.forEach(function(t){t&&t(n,i)}),o.ready||(o.ready=!0,o.readyCbs.forEach(function(t){t(n)}))},function(t){r&&r(t),t&&!o.ready&&(kt(t,mt.redirected)&&i===d||(o.ready=!0,o.readyErrorCbs.forEach(function(e){e(t)})))})},jt.prototype.confirmTransition=function(t,e,r){var n=this,o=this.current;this.pending=t;var i,a,u=function(t){!kt(t)&&Rt(t)&&(n.errorCbs.length?n.errorCbs.forEach(function(e){e(t)}):console.error(t)),r&&r(t)},s=t.matched.length-1,c=o.matched.length-1;if(m(t,o)&&s===c&&t.matched[s]===o.matched[c])return this.ensureURL(),u(((a=bt(i=o,t,mt.duplicated,'Avoided redundant navigation to current location: "'+i.fullPath+'".')).name="NavigationDuplicated",a));var p=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r0)){var e=this.router,r=e.options.scrollBehavior,n=lt&&r;n&&this.listeners.push(nt());var o=function(){var r=t.current,o=Tt(t.base);t.current===d&&o===t._startLocation||t.transitionTo(o,function(t){n&&ot(e,t,r,!0)})};window.addEventListener("popstate",o),this.listeners.push(function(){window.removeEventListener("popstate",o)})}},e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){dt(b(n.base+t.fullPath)),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){vt(b(n.base+t.fullPath)),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.ensureURL=function(t){if(Tt(this.base)!==this.current.fullPath){var e=b(this.base+this.current.fullPath);t?dt(e):vt(e)}},e.prototype.getCurrentLocation=function(){return Tt(this.base)},e}(jt);function Tt(t){var e=decodeURI(window.location.pathname);return t&&0===e.toLowerCase().indexOf(t.toLowerCase())&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}var Lt=function(t){function e(e,r,n){t.call(this,e,r),n&&function(t){var e=Tt(t);if(!/^\/#/.test(e))return window.location.replace(b(t+"/#"+e)),!0}(this.base)||qt()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this;if(!(this.listeners.length>0)){var e=this.router.options.scrollBehavior,r=lt&&e;r&&this.listeners.push(nt());var n=function(){var e=t.current;qt()&&t.transitionTo(Ut(),function(n){r&&ot(t.router,n,e,!0),lt||Vt(n.fullPath)})},o=lt?"popstate":"hashchange";window.addEventListener(o,n),this.listeners.push(function(){window.removeEventListener(o,n)})}},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Mt(t.fullPath),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Vt(t.fullPath),ot(n.router,t,o,!1),e&&e(t)},r)},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;Ut()!==e&&(t?Mt(e):Vt(e))},e.prototype.getCurrentLocation=function(){return Ut()},e}(jt);function qt(){var t=Ut();return"/"===t.charAt(0)||(Vt("/"+t),!1)}function Ut(){var t=window.location.href,e=t.indexOf("#");if(e<0)return"";var r=(t=t.slice(e+1)).indexOf("?");if(r<0){var n=t.indexOf("#");t=n>-1?decodeURI(t.slice(0,n))+t.slice(n):decodeURI(t)}else t=decodeURI(t.slice(0,r))+t.slice(r);return t}function It(t){var e=window.location.href,r=e.indexOf("#");return(r>=0?e.slice(0,r):e)+"#"+t}function Mt(t){lt?dt(It(t)):window.location.hash=t}function Vt(t){lt?vt(It(t)):window.location.replace(It(t))}var Bt=function(t){function e(e,r){t.call(this,e,r),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,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)},r)},e.prototype.go=function(t){var e=this,r=this.index+t;if(!(r<0||r>=this.stack.length)){var n=this.stack[r];this.confirmTransition(n,function(){var t=e.current;e.index=r,e.updateRoute(n),e.router.afterHooks.forEach(function(e){e&&e(n,t)})},function(t){kt(t,mt.duplicated)&&(e.index=r)})}},e.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},e.prototype.ensureURL=function(){},e}(jt),Ht=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=X(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!lt&&!1!==t.fallback,this.fallback&&(e="hash"),K||(e="abstract"),this.mode=e,e){case"history":this.history=new Pt(this,t.base);break;case"hash":this.history=new Lt(this,t.base,this.fallback);break;case"abstract":this.history=new Bt(this,t.base)}},Ft={currentRoute:{configurable:!0}};function Nt(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}return Ht.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},Ft.currentRoute.get=function(){return this.history&&this.history.current},Ht.prototype.init=function(t){var e=this;if(this.apps.push(t),t.$once("hook:destroyed",function(){var r=e.apps.indexOf(t);r>-1&&e.apps.splice(r,1),e.app===t&&(e.app=e.apps[0]||null),e.app||e.history.teardown()}),!this.app){this.app=t;var r=this.history;if(r instanceof Pt||r instanceof Lt){var n=function(t){r.setupListeners(),function(t){var n=r.current,o=e.options.scrollBehavior;lt&&o&&"fullPath"in t&&ot(e,t,n,!1)}(t)};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen(function(t){e.apps.forEach(function(e){e._route=t})})}},Ht.prototype.beforeEach=function(t){return Nt(this.beforeHooks,t)},Ht.prototype.beforeResolve=function(t){return Nt(this.resolveHooks,t)},Ht.prototype.afterEach=function(t){return Nt(this.afterHooks,t)},Ht.prototype.onReady=function(t,e){this.history.onReady(t,e)},Ht.prototype.onError=function(t){this.history.onError(t)},Ht.prototype.push=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise(function(e,r){n.history.push(t,e,r)});this.history.push(t,e,r)},Ht.prototype.replace=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise(function(e,r){n.history.replace(t,e,r)});this.history.replace(t,e,r)},Ht.prototype.go=function(t){this.history.go(t)},Ht.prototype.back=function(){this.go(-1)},Ht.prototype.forward=function(){this.go(1)},Ht.prototype.getMatchedComponents=function(t){var e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Ht.prototype.resolve=function(t,e,r){var n=V(t,e=e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:function(t,e,r){var n="hash"===r?"#"+e:e;return t?b(t+"/"+n):n}(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},Ht.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==d&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(Ht.prototype,Ft),Ht.install=function t(r){if(!t.installed||B!==r){t.installed=!0,B=r;var n=function(t){return void 0!==t},o=function(t,e){var r=t.$options._parentVnode;n(r)&&n(r=r.data)&&n(r=r.registerRouteInstance)&&r(t,e)};r.mixin({beforeCreate:function(){n(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),r.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,o(this,this)},destroyed:function(){o(this)}}),Object.defineProperty(r.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(r.prototype,"$route",{get:function(){return this._routerRoot._route}}),r.component("RouterView",e),r.component("RouterLink",z);var i=r.config.optionMergeStrategies;i.beforeRouteEnter=i.beforeRouteLeave=i.beforeRouteUpdate=i.created}},Ht.version="3.4.5",Ht.isNavigationFailure=kt,Ht.NavigationFailureType=mt,K&&window.Vue&&window.Vue.use(Ht),Ht},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).VueRouter=e(); \ No newline at end of file +var t,e;t=this,e=function(){"use strict";function t(t,e){for(var r in e)t[r]=e[r];return t}var e=/[!'()*]/g,r=function(t){return"%"+t.charCodeAt(0).toString(16)},n=/%2C/g,o=function(t){return encodeURIComponent(t).replace(e,r).replace(n,",")};function i(t){try{return decodeURIComponent(t)}catch(t){}return t}var a=function(t){return null==t||"object"==typeof t?t:String(t)};function u(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var r=t.replace(/\+/g," ").split("="),n=i(r.shift()),o=r.length>0?i(r.join("=")):null;void 0===e[n]?e[n]=o:Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]}),e):e}function s(t){var e=t?Object.keys(t).map(function(e){var r=t[e];if(void 0===r)return"";if(null===r)return o(e);if(Array.isArray(r)){var n=[];return r.forEach(function(t){void 0!==t&&(null===t?n.push(o(e)):n.push(o(e)+"="+o(t)))}),n.join("&")}return o(e)+"="+o(r)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}var c=/\/?$/;function p(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=f(i)}catch(t){}var a={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:i,params:e.params||{},fullPath:d(e,o),matched:t?l(t):[]};return r&&(a.redirectedFrom=d(r,o)),Object.freeze(a)}function f(t){if(Array.isArray(t))return t.map(f);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=f(t[r]);return e}return t}var h=p(null,{path:"/"});function l(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function d(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;return void 0===o&&(o=""),(r||"/")+(e||s)(n)+o}function v(t,e){return e===h?t===e:!!e&&(t.path&&e.path?t.path.replace(c,"")===e.path.replace(c,"")&&t.hash===e.hash&&y(t.query,e.query):!(!t.name||!e.name)&&t.name===e.name&&t.hash===e.hash&&y(t.query,e.query)&&y(t.params,e.params))}function y(t,e){if(void 0===t&&(t={}),void 0===e&&(e={}),!t||!e)return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(r){var n=t[r],o=e[r];return null==n||null==o?n===o:"object"==typeof n&&"object"==typeof o?y(n,o):String(n)===String(o)})}function m(t){for(var e=0;e=0&&(e=t.slice(n),t=t.slice(0,n));var o=t.indexOf("?");return o>=0&&(r=t.slice(o+1),t=t.slice(0,o)),{path:t,query:r,hash:e}}(i.path||""),h=r&&r.path||"/",l=f.path?b(f.path,h,n||i.append):h,d=function(t,e,r){void 0===e&&(e={});var n,o=r||u;try{n=o(t||"")}catch(t){n={}}for(var i in e){var s=e[i];n[i]=Array.isArray(s)?s.map(a):a(s)}return n}(f.query,i.query,o&&o.options.parseQuery),v=i.hash||f.hash;return v&&"#"!==v.charAt(0)&&(v="#"+v),{_normalized:!0,path:l,query:d,hash:v}}var H,F=[String,Object],N=[String,Array],z=function(){},D={name:"RouterLink",props:{to:{type:F,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,ariaCurrentValue:{type:String,default:"page"},event:{type:N,default:"click"}},render:function(e){var r=this,n=this.$router,o=this.$route,i=n.resolve(this.to,o,this.append),a=i.location,u=i.route,s=i.href,f={},h=n.options.linkActiveClass,l=n.options.linkExactActiveClass,d=null==h?"router-link-active":h,y=null==l?"router-link-exact-active":l,m=null==this.activeClass?d:this.activeClass,g=null==this.exactActiveClass?y:this.exactActiveClass,w=u.redirectedFrom?p(null,B(u.redirectedFrom),null,n):u;f[g]=v(o,w),f[m]=this.exact?f[g]:function(t,e){return 0===t.path.replace(c,"/").indexOf(e.path.replace(c,"/"))&&(!e.hash||t.hash===e.hash)&&function(t,e){for(var r in e)if(!(r in t))return!1;return!0}(t.query,e.query)}(o,w);var b=f[g]?this.ariaCurrentValue:null,x=function(t){K(t)&&(r.replace?n.replace(a,z):n.push(a,z))},k={click:K};Array.isArray(this.event)?this.event.forEach(function(t){k[t]=x}):k[this.event]=x;var R={class:f},E=!this.$scopedSlots.$hasNormal&&this.$scopedSlots.default&&this.$scopedSlots.default({href:s,route:u,navigate:x,isActive:f[m],isExactActive:f[g]});if(E){if(1===E.length)return E[0];if(E.length>1||!E.length)return 0===E.length?e():e("span",{},E)}if("a"===this.tag)R.on=k,R.attrs={href:s,"aria-current":b};else{var C=function t(e){if(e)for(var r,n=0;n-1&&(u.params[h]=r.params[h]);return u.path=V(p.path,u.params),s(p,u,a)}if(u.path){u.params={};for(var l=0;l=t.length?r():t[o]?e(t[o],function(){n(o+1)}):n(o+1)};n(0)}var gt={redirected:2,aborted:4,cancelled:8,duplicated:16};function wt(t,e){return xt(t,e,gt.redirected,'Redirected when going from "'+t.fullPath+'" to "'+function(t){if("string"==typeof t)return t;if("path"in t)return t.path;var e={};return kt.forEach(function(r){r in t&&(e[r]=t[r])}),JSON.stringify(e,null,2)}(e)+'" via a navigation guard.')}function bt(t,e){return xt(t,e,gt.cancelled,'Navigation cancelled from "'+t.fullPath+'" to "'+e.fullPath+'" with a new navigation.')}function xt(t,e,r,n){var o=new Error(n);return o._isRouter=!0,o.from=t,o.to=e,o.type=r,o}var kt=["params","query","hash"];function Rt(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function Et(t,e){return Rt(t)&&t._isRouter&&(null==e||t.type===e)}function Ct(t){return function(e,r,n){var o=!1,i=0,a=null;At(t,function(t,e,r,u){if("function"==typeof t&&void 0===t.cid){o=!0,i++;var s,c=jt(function(e){var o;((o=e).__esModule||_t&&"Module"===o[Symbol.toStringTag])&&(e=e.default),t.resolved="function"==typeof e?e:H.extend(e),r.components[u]=e,--i<=0&&n()}),p=jt(function(t){var e="Failed to resolve async component "+u+": "+t;a||(a=Rt(t)?t:new Error(e),n(a))});try{s=t(c,p)}catch(t){p(t)}if(s)if("function"==typeof s.then)s.then(c,p);else{var f=s.component;f&&"function"==typeof f.then&&f.then(c,p)}}}),o||n()}}function At(t,e){return Ot(t.map(function(t){return Object.keys(t.components).map(function(r){return e(t.components[r],t.instances[r],t,r)})}))}function Ot(t){return Array.prototype.concat.apply([],t)}var _t="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag;function jt(t){var e=!1;return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(!e)return e=!0,t.apply(this,r)}}var St=function(t,e){this.router=t,this.base=function(t){if(!t)if(J){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}(e),this.current=h,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[],this.listeners=[]};function $t(t,e,r,n){var o=At(t,function(t,n,o,i){var a=function(t,e){return"function"!=typeof t&&(t=H.extend(t)),t.options[e]}(t,e);if(a)return Array.isArray(a)?a.map(function(t){return r(t,n,o,i)}):r(a,n,o,i)});return Ot(n?o.reverse():o)}function Pt(t,e){if(e)return function(){return t.apply(e,arguments)}}St.prototype.listen=function(t){this.cb=t},St.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},St.prototype.onError=function(t){this.errorCbs.push(t)},St.prototype.transitionTo=function(t,e,r){var n,o=this;try{n=this.router.match(t,this.current)}catch(t){throw this.errorCbs.forEach(function(e){e(t)}),t}var i=this.current;this.confirmTransition(n,function(){o.updateRoute(n),e&&e(n),o.ensureURL(),o.router.afterHooks.forEach(function(t){t&&t(n,i)}),o.ready||(o.ready=!0,o.readyCbs.forEach(function(t){t(n)}))},function(t){r&&r(t),t&&!o.ready&&(Et(t,gt.redirected)&&i===h||(o.ready=!0,o.readyErrorCbs.forEach(function(e){e(t)})))})},St.prototype.confirmTransition=function(t,e,r){var n=this,o=this.current;this.pending=t;var i,a,u=function(t){!Et(t)&&Rt(t)&&(n.errorCbs.length?n.errorCbs.forEach(function(e){e(t)}):console.error(t)),r&&r(t)},s=t.matched.length-1,c=o.matched.length-1;if(v(t,o)&&s===c&&t.matched[s]===o.matched[c])return this.ensureURL(),u(((a=xt(i=o,t,gt.duplicated,'Avoided redundant navigation to current location: "'+i.fullPath+'".')).name="NavigationDuplicated",a));var p=function(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r0)){var e=this.router,r=e.options.scrollBehavior,n=dt&&r;n&&this.listeners.push(ot());var o=function(){var r=t.current,o=Tt(t.base);t.current===h&&o===t._startLocation||t.transitionTo(o,function(t){n&&it(e,t,r,!0)})};window.addEventListener("popstate",o),this.listeners.push(function(){window.removeEventListener("popstate",o)})}},e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){vt(x(n.base+t.fullPath)),it(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){yt(x(n.base+t.fullPath)),it(n.router,t,o,!1),e&&e(t)},r)},e.prototype.ensureURL=function(t){if(Tt(this.base)!==this.current.fullPath){var e=x(this.base+this.current.fullPath);t?vt(e):yt(e)}},e.prototype.getCurrentLocation=function(){return Tt(this.base)},e}(St);function Tt(t){var e=window.location.pathname;return t&&0===e.toLowerCase().indexOf(t.toLowerCase())&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}var qt=function(t){function e(e,r,n){t.call(this,e,r),n&&function(t){var e=Tt(t);if(!/^\/#/.test(e))return window.location.replace(x(t+"/#"+e)),!0}(this.base)||Ut()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this;if(!(this.listeners.length>0)){var e=this.router.options.scrollBehavior,r=dt&&e;r&&this.listeners.push(ot());var n=function(){var e=t.current;Ut()&&t.transitionTo(It(),function(n){r&&it(t.router,n,e,!0),dt||Bt(n.fullPath)})},o=dt?"popstate":"hashchange";window.addEventListener(o,n),this.listeners.push(function(){window.removeEventListener(o,n)})}},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Vt(t.fullPath),it(n.router,t,o,!1),e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Bt(t.fullPath),it(n.router,t,o,!1),e&&e(t)},r)},e.prototype.go=function(t){window.history.go(t)},e.prototype.ensureURL=function(t){var e=this.current.fullPath;It()!==e&&(t?Vt(e):Bt(e))},e.prototype.getCurrentLocation=function(){return It()},e}(St);function Ut(){var t=It();return"/"===t.charAt(0)||(Bt("/"+t),!1)}function It(){var t=window.location.href,e=t.indexOf("#");return e<0?"":t=t.slice(e+1)}function Mt(t){var e=window.location.href,r=e.indexOf("#");return(r>=0?e.slice(0,r):e)+"#"+t}function Vt(t){dt?vt(Mt(t)):window.location.hash=t}function Bt(t){dt?yt(Mt(t)):window.location.replace(Mt(t))}var Ht=function(t){function e(e,r){t.call(this,e,r),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,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++,e&&e(t)},r)},e.prototype.replace=function(t,e,r){var n=this;this.transitionTo(t,function(t){n.stack=n.stack.slice(0,n.index).concat(t),e&&e(t)},r)},e.prototype.go=function(t){var e=this,r=this.index+t;if(!(r<0||r>=this.stack.length)){var n=this.stack[r];this.confirmTransition(n,function(){var t=e.current;e.index=r,e.updateRoute(n),e.router.afterHooks.forEach(function(e){e&&e(n,t)})},function(t){Et(t,gt.duplicated)&&(e.index=r)})}},e.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},e.prototype.ensureURL=function(){},e}(St),Ft=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=Y(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!dt&&!1!==t.fallback,this.fallback&&(e="hash"),J||(e="abstract"),this.mode=e,e){case"history":this.history=new Lt(this,t.base);break;case"hash":this.history=new qt(this,t.base,this.fallback);break;case"abstract":this.history=new Ht(this,t.base)}},Nt={currentRoute:{configurable:!0}};function zt(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}return Ft.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},Nt.currentRoute.get=function(){return this.history&&this.history.current},Ft.prototype.init=function(t){var e=this;if(this.apps.push(t),t.$once("hook:destroyed",function(){var r=e.apps.indexOf(t);r>-1&&e.apps.splice(r,1),e.app===t&&(e.app=e.apps[0]||null),e.app||e.history.teardown()}),!this.app){this.app=t;var r=this.history;if(r instanceof Lt||r instanceof qt){var n=function(t){r.setupListeners(),function(t){var n=r.current,o=e.options.scrollBehavior;dt&&o&&"fullPath"in t&&it(e,t,n,!1)}(t)};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen(function(t){e.apps.forEach(function(e){e._route=t})})}},Ft.prototype.beforeEach=function(t){return zt(this.beforeHooks,t)},Ft.prototype.beforeResolve=function(t){return zt(this.resolveHooks,t)},Ft.prototype.afterEach=function(t){return zt(this.afterHooks,t)},Ft.prototype.onReady=function(t,e){this.history.onReady(t,e)},Ft.prototype.onError=function(t){this.history.onError(t)},Ft.prototype.push=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise(function(e,r){n.history.push(t,e,r)});this.history.push(t,e,r)},Ft.prototype.replace=function(t,e,r){var n=this;if(!e&&!r&&"undefined"!=typeof Promise)return new Promise(function(e,r){n.history.replace(t,e,r)});this.history.replace(t,e,r)},Ft.prototype.go=function(t){this.history.go(t)},Ft.prototype.back=function(){this.go(-1)},Ft.prototype.forward=function(){this.go(1)},Ft.prototype.getMatchedComponents=function(t){var e=t?t.matched?t:this.resolve(t).route:this.currentRoute;return e?[].concat.apply([],e.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Ft.prototype.resolve=function(t,e,r){var n=B(t,e=e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:function(t,e,r){var n="hash"===r?"#"+e:e;return t?x(t+"/"+n):n}(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},Ft.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==h&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(Ft.prototype,Nt),Ft.install=function t(e){if(!t.installed||H!==e){t.installed=!0,H=e;var r=function(t){return void 0!==t},n=function(t,e){var n=t.$options._parentVnode;r(n)&&r(n=n.data)&&r(n=n.registerRouteInstance)&&n(t,e)};e.mixin({beforeCreate:function(){r(this.$options.router)?(this._routerRoot=this,this._router=this.$options.router,this._router.init(this),e.util.defineReactive(this,"_route",this._router.history.current)):this._routerRoot=this.$parent&&this.$parent._routerRoot||this,n(this,this)},destroyed:function(){n(this)}}),Object.defineProperty(e.prototype,"$router",{get:function(){return this._routerRoot._router}}),Object.defineProperty(e.prototype,"$route",{get:function(){return this._routerRoot._route}}),e.component("RouterView",g),e.component("RouterLink",D);var o=e.config.optionMergeStrategies;o.beforeRouteEnter=o.beforeRouteLeave=o.beforeRouteUpdate=o.created}},Ft.version="3.4.6",Ft.isNavigationFailure=Et,Ft.NavigationFailureType=gt,J&&window.Vue&&window.Vue.use(Ft),Ft},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).VueRouter=e(); \ No newline at end of file