From b7073528fd573c5b0fb5cd13d85d5d2e3395d32c Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 11 Oct 2017 18:18:51 -0400 Subject: [PATCH 1/9] docs: update version info --- docs/en/SUMMARY.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/SUMMARY.md b/docs/en/SUMMARY.md index 29f6cfcd3..d64207969 100644 --- a/docs/en/SUMMARY.md +++ b/docs/en/SUMMARY.md @@ -1,7 +1,7 @@ # vue-router 2 - -> Note: vue-router@2.x only works with Vue 2.x. Docs for 0.7.x is [here](https://github.com/vuejs/vue-router/tree/1.0/docs/en). - + +> Note: for TypeScript users, vue-router@>= 3.0 requires vue@>=2.5, and vice versa. + **[Release Notes](https://github.com/vuejs/vue-router/releases)** - [Installation](installation.md) From 17e13a8a86d2ac2ecf4553b9c4cc3d88a6c575f5 Mon Sep 17 00:00:00 2001 From: Alexander Sokolov Date: Thu, 12 Oct 2017 12:45:21 +0300 Subject: [PATCH 2/9] [RU] Translation update (#1802) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * navigation-guards.md нумерация версии * history-mode.md правки по IIS * lazy-loading HTTPS * dynamic-mathcing.md HTTPS * getting-started.md HTTPS * navigation.md мелкие правки * nested-routes.md HTTPS * navigation-guards.md правки * history-mode.md кавычки и добавлена секция про Firebase * redirect-and-alias.md добавлено уточнение * SUMMARY.md правка * options.md обновлён пример сигнатуры * getting-started.md добавлены новые правки * navigation-guards.md новые правки * scroll-behavior.md новые правки --- docs/ru/SUMMARY.md | 6 +++--- docs/ru/advanced/navigation-guards.md | 23 ++++++++++++++++++++++- docs/ru/advanced/scroll-behavior.md | 20 +++++++++++++++++++- docs/ru/api/options.md | 9 +++++++-- docs/ru/essentials/getting-started.md | 23 +++++++++++++++++++++++ 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/docs/ru/SUMMARY.md b/docs/ru/SUMMARY.md index 9eeca8ba6..91c1cc97f 100644 --- a/docs/ru/SUMMARY.md +++ b/docs/ru/SUMMARY.md @@ -1,7 +1,7 @@ # Vue-router 2 - -> Примечание: Vue-router@2.x работает только с Vue 2.x. Документация для версии 0.7.x находится [здесь (en)](https://github.com/vuejs/vue-router/tree/1.0/docs/en). - + +> Примечание: для пользователей TypeScript, vue-router@>= 3.0 требуется vue@>=2.5, и наоборот. + **[История изменений](https://github.com/vuejs/vue-router/releases)** - [Введение](README.md) diff --git a/docs/ru/advanced/navigation-guards.md b/docs/ru/advanced/navigation-guards.md index 47dbb3696..fc7d96e0e 100644 --- a/docs/ru/advanced/navigation-guards.md +++ b/docs/ru/advanced/navigation-guards.md @@ -115,7 +115,28 @@ beforeRouteEnter (to, from, next) { } ``` -Внутри `beforeRouteLeave` можно обращаться к `this` напрямую. Этот сторожевой хук обычно используется для предотвращения случайного ухода пользователя с пути, содержащего несохранённые отредактированные данные. Переход можно отменить, вызвав `next(false)`. +Обратите внимание, что `beforeRouteEnter` — единственный хук, который поддерживает передачу коллбэка в `next`. Для `beforeRouteUpdate` и `beforeRouteLeave`, `this` уже доступен, поэтому передача коллбэка не требуется и поэтому *не поддерживается*: + +```js +beforeRouteUpdate (to, from, next) { + // просто используйте `this` + this.name = to.params.name + next() +} +``` + +**Сторожевой хук ухода со страницы** обычно используется для предотвращения случайного ухода пользователя со страницы с несохранёнными изменениями. Навигацию можно отменить вызовом `next(false)`. + +```js +beforeRouteLeave (to, from , next) { + const answer = window.confirm('Вы действительно хотите уйти? У вас есть несохранённые изменения!') + if (answer) { + next() + } else { + next(false) + } +} +``` ### Полная цепочка обработки навигации diff --git a/docs/ru/advanced/scroll-behavior.md b/docs/ru/advanced/scroll-behavior.md index 0f64c5a22..c15e381ed 100644 --- a/docs/ru/advanced/scroll-behavior.md +++ b/docs/ru/advanced/scroll-behavior.md @@ -2,7 +2,7 @@ При переходе между страницами в рамках клиентского роутинга, можно сохранять позицию скроллинга для каждой записи в истории (что обычно делают браузеры при работе с традиционными приложениями), или же проматывать страницу вверх. `Vue-router` позволяет использовать оба варианта, и даже более того — позволяет полностью настроить поведение скроллинга при навигации. -**Замечание: эта возможность работает только в режиме HTML5 history mode.** +**Замечание: эта возможность работает если браузер поддерживает `history.pushState`.** При создании экземпляра роутера, вы можете указать функцию `scrollBehavior`: @@ -60,3 +60,21 @@ scrollBehavior (to, from, savedPosition) { ``` Можно также использовать [метаданные путей](meta.md) для более сложного управления скроллингом. Полная реализация подхода содержится в [этом примере](https://github.com/vuejs/vue-router/blob/dev/examples/scroll-behavior/app.js). + +### Асинхронный скроллинг + +> Добавлено в версии 2.8.0 + +Вы также можете вернуть Promise, который разрешится дескриптором с желаемой позицией: + +``` js +scrollBehavior (to, from, savedPosition) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve({ x: 0, y: 0 }) + }, 500) + }) +} +``` + +Это возможно связать с событиями из сменяющегося компонента-страниц, чтобы сделать поведение прокрутки более сочетаемым с вашими анимациями перехода между страницами, но из-за множества возможных вариантов и комплексности примеров, мы просто предоставляем этот просто пример чтобы показать где можно разместить собственную реализацию. \ No newline at end of file diff --git a/docs/ru/api/options.md b/docs/ru/api/options.md index 22b1e032d..d1bc5afa7 100644 --- a/docs/ru/api/options.md +++ b/docs/ru/api/options.md @@ -74,11 +74,16 @@ Сигнатура: ``` - ( + type PositionDescriptor = + { x: number, y: number } | + { selector: string } | + ?{} + + type scrollBehaviorHandler = ( to: Route, from: Route, savedPosition?: { x: number, y: number } - ) => { x: number, y: number } | { selector: string } | ?{} + ) => PositionDescriptor | Promise ``` Для подробностей см. [Скроллинг](../advanced/scroll-behavior.md). diff --git a/docs/ru/essentials/getting-started.md b/docs/ru/essentials/getting-started.md index cb640dba6..ff7c7a8f6 100644 --- a/docs/ru/essentials/getting-started.md +++ b/docs/ru/essentials/getting-started.md @@ -63,6 +63,29 @@ const app = new Vue({ // Всё, приложение работает! ;) ``` +Установив маршрутизатор, мы можем получить к нему доступ через `this.$router`, а также к текущему маршруту через `this.$route` внутри любого компонента: + +```js +// Home.vue +export default { + computed: { + username () { + // Мы скоро разберём что такое `params` + return this.$route.params.username + } + }, + methods: { + goBack () { + window.history.length > 1 + ? this.$router.go(-1) + : this.$router.push('/') + } + } +} +``` + +В документации мы будем часть использовать экземпляр `router` (маршрутизатора). Имейте ввиду, что `this.$router` в точности тоже самое, что и `router`. Причина, по которой мы используем `this.$router` заключается в том, что мы не хотим импортировать маршрутизатор в каждом компонент, в котором потребуется управлять маршрутизацией. + Вживую этот пример доступен [здесь](https://jsfiddle.net/yyx990803/xgrjzsup/). Обратите внимание, что `` автоматически получает класс `.router-link-active` при совпадении пути. Подробнее об этом можно узнать в [справочнике API](../api/router-link.md). From 64d9cd1ea60072f1b722ecfc6a6da837f47e5bf9 Mon Sep 17 00:00:00 2001 From: Alexander Sokolov Date: Thu, 12 Oct 2017 15:12:07 +0300 Subject: [PATCH 3/9] [RU] Fix typos (#1803) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * navigation-guards.md нумерация версии * history-mode.md правки по IIS * lazy-loading HTTPS * dynamic-mathcing.md HTTPS * getting-started.md HTTPS * navigation.md мелкие правки * nested-routes.md HTTPS * navigation-guards.md правки * history-mode.md кавычки и добавлена секция про Firebase * redirect-and-alias.md добавлено уточнение * SUMMARY.md правка * options.md обновлён пример сигнатуры * getting-started.md добавлены новые правки * navigation-guards.md новые правки * scroll-behavior.md новые правки * getting-started.md опечатки --- docs/ru/essentials/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ru/essentials/getting-started.md b/docs/ru/essentials/getting-started.md index ff7c7a8f6..446e2c418 100644 --- a/docs/ru/essentials/getting-started.md +++ b/docs/ru/essentials/getting-started.md @@ -84,7 +84,7 @@ export default { } ``` -В документации мы будем часть использовать экземпляр `router` (маршрутизатора). Имейте ввиду, что `this.$router` в точности тоже самое, что и `router`. Причина, по которой мы используем `this.$router` заключается в том, что мы не хотим импортировать маршрутизатор в каждом компонент, в котором потребуется управлять маршрутизацией. +В документации мы будем часто использовать экземпляр `router` (маршрутизатора). Имейте ввиду, что `this.$router` в точности тоже самое, что и `router`. Причина, по которой мы используем `this.$router` заключается в том, что мы не хотим импортировать маршрутизатор в каждом компоненте, в котором потребуется управлять маршрутизацией. Вживую этот пример доступен [здесь](https://jsfiddle.net/yyx990803/xgrjzsup/). From ccf7a8b1c5b5ae30db4d3a2b58ab55e7aafa6319 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Oct 2017 00:35:01 -0400 Subject: [PATCH 4/9] build: use uglify preamble option --- build/build.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/build.js b/build/build.js index 7e43ccf59..16487c40c 100644 --- a/build/build.js +++ b/build/build.js @@ -32,8 +32,9 @@ function buildEntry ({ input, output }) { .then(bundle => bundle.generate(output)) .then(({ code }) => { if (isProd) { - var minified = (output.banner ? output.banner + '\n' : '') + uglify.minify(code, { + var minified = uglify.minify(code, { output: { + preamble: output.banner, /* eslint-disable camelcase */ ascii_only: true /* eslint-enable camelcase */ From 7ac16f732a0f68af484cc7e23ac574d4d7e7470f Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Oct 2017 00:35:19 -0400 Subject: [PATCH 5/9] update vue to 2.5 --- package-lock.json | 10 ++++++---- package.json | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a98ae080..5aef0579a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8086,7 +8086,9 @@ } }, "vue": { - "version": "github:vuejs/vue#ea3a70b2d59b9d4ecae2bd2438f89dc16e1e1394", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/vue/-/vue-2.5.0.tgz", + "integrity": "sha512-KngZQLLe/N2Bvl3qu0xgqQHemm9MNz9y73D7yJ5tVavOKyhSgCLARYzrXJzYtoeadUSrItzV36VrHywLGVUx7w==", "dev": true }, "vue-hot-reload-api": { @@ -8181,9 +8183,9 @@ } }, "vue-template-compiler": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.4.4.tgz", - "integrity": "sha512-XdHsNi8Z5WqwuFl/Z5eLKgE2DOEEOdMk1aA459uSgvwyy+pjKLBlQWsUpAtoR6o6Wmpujw6NtinAUGuqSTituQ==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.5.0.tgz", + "integrity": "sha512-W4hDoXXpCwfilO1MRTDM4EHm1DC1mU1wS8WyvEo119cUtxdaPuq/dD0OJbSEIkeW8fdT07qGCSnLOfPlmrKRqw==", "dev": true, "requires": { "de-indent": "1.0.2", diff --git a/package.json b/package.json index aae1b68dc..be9c6d26c 100644 --- a/package.json +++ b/package.json @@ -70,9 +70,9 @@ "selenium-server": "^2.53.1", "typescript": "^2.5.3", "uglify-js": "^3.1.3", - "vue": "github:vuejs/vue#dev", + "vue": "^2.5.0", "vue-loader": "^13.3.0", - "vue-template-compiler": "^2.4.4", + "vue-template-compiler": "^2.5.0", "webpack": "^3.7.1", "webpack-dev-middleware": "^1.9.0" } From 02ff7929226225e432ff340e1a151e53e7b28f75 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Oct 2017 11:27:18 -0400 Subject: [PATCH 6/9] fix: fix props-passing regression fix #1800 --- examples/route-props/Hello.vue | 4 ++-- examples/route-props/app.js | 16 ++-------------- src/components/view.js | 25 ++++++++++++++++++------- test/e2e/specs/route-props.js | 18 +++++++++++++----- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/examples/route-props/Hello.vue b/examples/route-props/Hello.vue index 1205c6da5..10207d4b7 100644 --- a/examples/route-props/Hello.vue +++ b/examples/route-props/Hello.vue @@ -1,6 +1,6 @@ @@ -14,4 +14,4 @@ export default { } } } - \ No newline at end of file + diff --git a/examples/route-props/app.js b/examples/route-props/app.js index 214e85147..8739b6526 100644 --- a/examples/route-props/app.js +++ b/examples/route-props/app.js @@ -11,18 +11,6 @@ function dynamicPropsFn (route) { } } -const Child = { - name: 'child', - props: { name: { default: 'name' }}, - template: `

Hello {{ name }}

` -} - -const Parent = { - name: 'parent', - components: { Child }, - template: `` -} - const router = new VueRouter({ mode: 'history', base: __dirname, @@ -31,7 +19,7 @@ const router = new VueRouter({ { path: '/hello/:name', component: Hello, props: true }, // Pass route.params to props { path: '/static', component: Hello, props: { name: 'world' }}, // static values { path: '/dynamic/:years', component: Hello, props: dynamicPropsFn }, // custom logic for mapping between route and props - { path: '/attrs', component: Parent, props: { name: 'attrs' }} + { path: '/attrs', component: Hello, props: { name: 'attrs' }} ] }) @@ -47,7 +35,7 @@ new Vue({
  • /dynamic/1
  • /attrs
  • - + ` }).$mount('#app') diff --git a/src/components/view.js b/src/components/view.js index fe134aaab..0534c5e55 100644 --- a/src/components/view.js +++ b/src/components/view.js @@ -68,13 +68,17 @@ export default { } // resolve props - data.props = resolveProps(route, matched.props && matched.props[name]) - data.attrs = {} - - for (const key in data.props) { - if (!('props' in component) || !(key in component.props)) { - data.attrs[key] = data.props[key] - delete data.props[key] + let propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]) + 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] + } } } @@ -102,3 +106,10 @@ function resolveProps (route, config) { } } } + +function extend (to, from) { + for (const key in from) { + to[key] = from[key] + } + return to +} diff --git a/test/e2e/specs/route-props.js b/test/e2e/specs/route-props.js index 77d35d0ea..3e324e69c 100644 --- a/test/e2e/specs/route-props.js +++ b/test/e2e/specs/route-props.js @@ -1,3 +1,5 @@ +const $attrs = ' { "foo": "123" }' + module.exports = { 'route-props': function (browser) { browser @@ -6,23 +8,29 @@ module.exports = { .assert.count('li a', 5) .assert.urlEquals('http://localhost:8080/route-props/') - .assert.containsText('.hello', 'Hello Vue!') + .assert.containsText('.hello', 'Hello Vue!' + $attrs) .click('li:nth-child(2) a') .assert.urlEquals('http://localhost:8080/route-props/hello/you') - .assert.containsText('.hello', 'Hello you') + .assert.containsText('.hello', 'Hello you' + $attrs) .click('li:nth-child(3) a') .assert.urlEquals('http://localhost:8080/route-props/static') - .assert.containsText('.hello', 'Hello world') + .assert.containsText('.hello', 'Hello world' + $attrs) .click('li:nth-child(4) a') .assert.urlEquals('http://localhost:8080/route-props/dynamic/1') - .assert.containsText('.hello', 'Hello ' + ((new Date()).getFullYear() + 1)+ '!') + .assert.containsText('.hello', 'Hello ' + ((new Date()).getFullYear() + 1)+ '!' + $attrs) .click('li:nth-child(5) a') .assert.urlEquals('http://localhost:8080/route-props/attrs') - .assert.containsText('.hello', 'Hello attrs') + .assert.containsText('.hello', 'Hello attrs' + $attrs) + + // should be consistent + .click('li:nth-child(4) a') + .click('li:nth-child(5) a') + .assert.urlEquals('http://localhost:8080/route-props/attrs') + .assert.containsText('.hello', 'Hello attrs' + $attrs) .end() } From eea2d82e76679f864f11d405dcb315792ccab424 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Oct 2017 12:22:10 -0400 Subject: [PATCH 7/9] run e2e in phantom by default --- test/e2e/runner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/runner.js b/test/e2e/runner.js index 1ec931f52..f2e751b11 100644 --- a/test/e2e/runner.js +++ b/test/e2e/runner.js @@ -10,7 +10,7 @@ if (args.indexOf('--config') === -1) { args = args.concat(['--config', 'test/e2e/nightwatch.config.js']) } if (args.indexOf('--env') === -1) { - args = args.concat(['--env', process.env.CIRCLECI ? 'phantomjs' : 'chrome']) + args = args.concat(['--env', 'phantomjs']) } var i = args.indexOf('--test') if (i > -1) { From c732135e9a07f7fb37deba89510a9e86de33bc15 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Oct 2017 12:24:05 -0400 Subject: [PATCH 8/9] [build] 3.0.1 --- dist/vue-router.common.js | 29 ++++++++++++++++++++--------- dist/vue-router.esm.js | 29 ++++++++++++++++++++--------- dist/vue-router.js | 29 ++++++++++++++++++++--------- dist/vue-router.min.js | 4 ++-- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/dist/vue-router.common.js b/dist/vue-router.common.js index 392bad118..c9eb5a168 100644 --- a/dist/vue-router.common.js +++ b/dist/vue-router.common.js @@ -1,5 +1,5 @@ /** - * vue-router v3.0.0 + * vue-router v3.0.1 * (c) 2017 Evan You * @license MIT */ @@ -96,13 +96,17 @@ var View = { }; // resolve props - data.props = resolveProps(route, matched.props && matched.props[name]); - data.attrs = {}; - - for (var key in data.props) { - if (!('props' in component) || !(key in component.props)) { - data.attrs[key] = data.props[key]; - delete data.props[key]; + var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]); + 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]; + } } } @@ -131,6 +135,13 @@ function resolveProps (route, config) { } } +function extend (to, from) { + for (var key in from) { + to[key] = from[key]; + } + return to +} + /* */ var encodeReserveRE = /[!'()*]/g; @@ -2605,7 +2616,7 @@ function createHref (base, fullPath, mode) { } VueRouter.install = install; -VueRouter.version = '3.0.0'; +VueRouter.version = '3.0.1'; if (inBrowser && window.Vue) { window.Vue.use(VueRouter); diff --git a/dist/vue-router.esm.js b/dist/vue-router.esm.js index fc0f28142..130c26b94 100644 --- a/dist/vue-router.esm.js +++ b/dist/vue-router.esm.js @@ -1,5 +1,5 @@ /** - * vue-router v3.0.0 + * vue-router v3.0.1 * (c) 2017 Evan You * @license MIT */ @@ -94,13 +94,17 @@ var View = { }; // resolve props - data.props = resolveProps(route, matched.props && matched.props[name]); - data.attrs = {}; - - for (var key in data.props) { - if (!('props' in component) || !(key in component.props)) { - data.attrs[key] = data.props[key]; - delete data.props[key]; + var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]); + 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]; + } } } @@ -129,6 +133,13 @@ function resolveProps (route, config) { } } +function extend (to, from) { + for (var key in from) { + to[key] = from[key]; + } + return to +} + /* */ var encodeReserveRE = /[!'()*]/g; @@ -2603,7 +2614,7 @@ function createHref (base, fullPath, mode) { } VueRouter.install = install; -VueRouter.version = '3.0.0'; +VueRouter.version = '3.0.1'; if (inBrowser && window.Vue) { window.Vue.use(VueRouter); diff --git a/dist/vue-router.js b/dist/vue-router.js index c81c8d12f..3285a7699 100644 --- a/dist/vue-router.js +++ b/dist/vue-router.js @@ -1,5 +1,5 @@ /** - * vue-router v3.0.0 + * vue-router v3.0.1 * (c) 2017 Evan You * @license MIT */ @@ -100,13 +100,17 @@ var View = { }; // resolve props - data.props = resolveProps(route, matched.props && matched.props[name]); - data.attrs = {}; - - for (var key in data.props) { - if (!('props' in component) || !(key in component.props)) { - data.attrs[key] = data.props[key]; - delete data.props[key]; + var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]); + 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]; + } } } @@ -135,6 +139,13 @@ function resolveProps (route, config) { } } +function extend (to, from) { + for (var key in from) { + to[key] = from[key]; + } + return to +} + /* */ var encodeReserveRE = /[!'()*]/g; @@ -2609,7 +2620,7 @@ function createHref (base, fullPath, mode) { } VueRouter.install = install; -VueRouter.version = '3.0.0'; +VueRouter.version = '3.0.1'; if (inBrowser && window.Vue) { window.Vue.use(VueRouter); diff --git a/dist/vue-router.min.js b/dist/vue-router.min.js index 487a12ac0..867a9787b 100644 --- a/dist/vue-router.min.js +++ b/dist/vue-router.min.js @@ -1,6 +1,6 @@ /** - * vue-router v3.0.0 + * vue-router v3.0.1 * (c) 2017 Evan You * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e){}function e(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function r(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}}function n(t,e,r){void 0===e&&(e={});var n,i=r||o;try{n=i(t||"")}catch(t){n={}}for(var a in e)n[a]=e[a];return n}function o(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var r=t.replace(/\+/g," ").split("="),n=Pt(r.shift()),o=r.length>0?Pt(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 i(t){var e=t?Object.keys(t).map(function(e){var r=t[e];if(void 0===r)return"";if(null===r)return Lt(e);if(Array.isArray(r)){var n=[];return r.forEach(function(t){void 0!==t&&(null===t?n.push(Lt(e)):n.push(Lt(e)+"="+Lt(t)))}),n.join("&")}return Lt(e)+"="+Lt(r)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function a(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=u(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:s(e,o),matched:t?c(t):[]};return r&&(a.redirectedFrom=s(r,o)),Object.freeze(a)}function u(t){if(Array.isArray(t))return t.map(u);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=u(t[r]);return e}return t}function c(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function s(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;void 0===o&&(o="");var a=e||i;return(r||"/")+a(n)+o}function p(t,e){return e===Mt?t===e:!!e&&(t.path&&e.path?t.path.replace(Ut,"")===e.path.replace(Ut,"")&&t.hash===e.hash&&f(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&f(t.query,e.query)&&f(t.params,e.params)))}function f(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"object"==typeof n&&"object"==typeof o?f(n,o):String(n)===String(o)})}function h(t,e){return 0===t.path.replace(Ut,"/").indexOf(e.path.replace(Ut,"/"))&&(!e.hash||t.hash===e.hash)&&l(t.query,e.query)}function l(t,e){for(var r in e)if(!(r in t))return!1;return!0}function d(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function y(t){if(t)for(var e,r=0;r=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}}function b(t){return t.replace(/\/\//g,"/")}function w(t,e){for(var r,n=[],o=0,i=0,a="",u=e&&e.delimiter||"/";null!=(r=Nt.exec(t));){var c=r[0],s=r[1],p=r.index;if(a+=t.slice(i,p),i=p+c.length,s)a+=s[1];else{var f=t[i],h=r[2],l=r[3],d=r[4],y=r[5],v=r[6],m=r[7];a&&(n.push(a),a="");var g=null!=h&&null!=f&&f!==h,b="+"===v||"*"===v,w="?"===v||"*"===v,x=r[2]||u,k=d||y;n.push({name:l||o++,prefix:h||"",delimiter:x,optional:w,repeat:b,partial:g,asterisk:!!m,pattern:k?O(k):m?".*":"[^"+E(x)+"]+?"})}}return i-1&&(o.params[h]=r.params[h]);if(u)return o.path=q(u.path,o.params,'named route "'+a+'"'),i(u,o,n)}else if(o.path){o.params={};for(var l=0;l=t.length?r():t[o]?e(t[o],function(){n(o+1)}):n(o+1)};n(0)}function it(t){return function(r,n,o){var i=!1,a=0,u=null;at(t,function(t,r,n,c){if("function"==typeof t&&void 0===t.cid){i=!0,a++;var s,p=st(function(e){ct(e)&&(e=e.default),t.resolved="function"==typeof e?e:_t.extend(e),n.components[c]=e,--a<=0&&o()}),f=st(function(t){var r="Failed to resolve async component "+c+": "+t;u||(u=e(t)?t:new Error(r),o(u))});try{s=t(p,f)}catch(t){f(t)}if(s)if("function"==typeof s.then)s.then(p,f);else{var h=s.component;h&&"function"==typeof h.then&&h.then(p,f)}}}),i||o()}}function at(t,e){return ut(t.map(function(t){return Object.keys(t.components).map(function(r){return e(t.components[r],t.instances[r],t,r)})}))}function ut(t){return Array.prototype.concat.apply([],t)}function ct(t){return t.__esModule||Zt&&"Module"===t[Symbol.toStringTag]}function st(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)}}function pt(t){if(!t)if(zt){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function ft(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r=0?e.slice(0,r):e)+"#"+t}function Ot(t){Yt?rt(Et(t)):window.location.hash=t}function Ct(t){Yt?nt(Et(t)):window.location.replace(Et(t))}function jt(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}function At(t,e,r){var n="hash"===r?"#"+e:e;return t?b(t+"/"+n):n}var _t,Tt={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,o=e.children,i=e.parent,a=e.data;a.routerView=!0;for(var u=i.$createElement,c=n.name,s=i.$route,p=i._routerViewCache||(i._routerViewCache={}),f=0,h=!1;i&&i._routerRoot!==i;)i.$vnode&&i.$vnode.data.routerView&&f++,i._inactive&&(h=!0),i=i.$parent;if(a.routerViewDepth=f,h)return u(p[c],a,o);var l=s.matched[f];if(!l)return p[c]=null,u();var d=p[c]=l.components[c];a.registerRouteInstance=function(t,e){var r=l.instances[c];(e&&r!==t||!e&&r===t)&&(l.instances[c]=e)},(a.hook||(a.hook={})).prepatch=function(t,e){l.instances[c]=e.componentInstance},a.props=r(s,l.props&&l.props[c]),a.attrs={};for(var y in a.props)"props"in d&&y in d.props||(a.attrs[y]=a.props[y],delete a.props[y]);return u(d,a,o)}},St=/[!'()*]/g,$t=function(t){return"%"+t.charCodeAt(0).toString(16)},qt=/%2C/g,Lt=function(t){return encodeURIComponent(t).replace(St,$t).replace(qt,",")},Pt=decodeURIComponent,Ut=/\/?$/,Mt=a(null,{path:"/"}),Ht=[String,Object],It=[String,Array],Vt={name:"router-link",props:{to:{type:Ht,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:It,default:"click"}},render:function(t){var e=this,r=this.$router,n=this.$route,o=r.resolve(this.to,n,this.append),i=o.location,u=o.route,c=o.href,s={},f=r.options.linkActiveClass,l=r.options.linkExactActiveClass,v=null==f?"router-link-active":f,m=null==l?"router-link-exact-active":l,g=null==this.activeClass?v:this.activeClass,b=null==this.exactActiveClass?m:this.exactActiveClass,w=i.path?a(null,i,null,r):u;s[b]=p(n,w),s[g]=this.exact?s[b]:h(n,w);var x=function(t){d(t)&&(e.replace?r.replace(i):r.push(i))},k={click:d};Array.isArray(this.event)?this.event.forEach(function(t){k[t]=x}):k[this.event]=x;var R={class:s};if("a"===this.tag)R.on=k,R.attrs={href:c};else{var E=y(this.$slots.default);if(E){E.isStatic=!1;var O=_t.util.extend;(E.data=O({},E.data)).on=k,(E.data.attrs=O({},E.data.attrs)).href=c}else R.on=k}return t(this.tag,R,this.$slots.default)}},zt="undefined"!=typeof window,Bt=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},Ft=$,Dt=w,Kt=R,Jt=S,Nt=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");Ft.parse=Dt,Ft.compile=function(t,e){return R(w(t,e))},Ft.tokensToFunction=Kt,Ft.tokensToRegExp=Jt;var Qt=Object.create(null),Xt=Object.create(null),Yt=zt&&function(){var 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&&"pushState"in window.history)}(),Wt=zt&&window.performance&&window.performance.now?window.performance:Date,Gt=Z(),Zt="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,te=function(t,e){this.router=t,this.base=pt(e),this.current=Mt,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};te.prototype.listen=function(t){this.cb=t},te.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},te.prototype.onError=function(t){this.errorCbs.push(t)},te.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(t){r&&r(t),t&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(e){e(t)}))})},te.prototype.confirmTransition=function(r,n,o){var i=this,a=this.current,u=function(r){e(r)&&(i.errorCbs.length?i.errorCbs.forEach(function(t){t(r)}):(t(!1,"uncaught error during route navigation:"),console.error(r))),o&&o(r)};if(p(r,a)&&r.matched.length===a.matched.length)return this.ensureURL(),u();var c=ft(this.current.matched,r.matched),s=c.updated,f=c.deactivated,h=c.activated,l=[].concat(dt(f),this.router.beforeHooks,yt(s),h.map(function(t){return t.beforeEnter}),it(h));this.pending=r;var d=function(t,n){if(i.pending!==r)return u();try{t(r,a,function(t){!1===t||e(t)?(i.ensureURL(!0),u(t)):"string"==typeof t||"object"==typeof t&&("string"==typeof t.path||"string"==typeof t.name)?(u(),"object"==typeof t&&t.replace?i.replace(t):i.push(t)):n(t)})}catch(t){u(t)}};ot(l,d,function(){var t=[];ot(mt(h,t,function(){return i.current===r}).concat(i.router.resolveHooks),d,function(){if(i.pending!==r)return u();i.pending=null,n(r),i.router.app&&i.router.app.$nextTick(function(){t.forEach(function(t){t()})})})})},te.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(r){r&&r(t,e)})};var ee=function(t){function e(e,r){var n=this;t.call(this,e,r);var o=e.options.scrollBehavior;o&&F();var i=wt(this.base);window.addEventListener("popstate",function(t){var r=n.current,a=wt(n.base);n.current===Mt&&a===i||n.transitionTo(a,function(t){o&&D(e,t,r,!0)})})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){rt(b(n.base+t.fullPath)),D(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){nt(b(n.base+t.fullPath)),D(n.router,t,o,!1),e&&e(t)},r)},e.prototype.ensureURL=function(t){if(wt(this.base)!==this.current.fullPath){var e=b(this.base+this.current.fullPath);t?rt(e):nt(e)}},e.prototype.getCurrentLocation=function(){return wt(this.base)},e}(te),re=function(t){function e(e,r,n){t.call(this,e,r),n&&xt(this.base)||kt()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this,e=this.router.options.scrollBehavior,r=Yt&&e;r&&F(),window.addEventListener(Yt?"popstate":"hashchange",function(){var e=t.current;kt()&&t.transitionTo(Rt(),function(n){r&&D(t.router,n,e,!0),Yt||Ct(n.fullPath)})})},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Ot(t.fullPath),D(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){Ct(t.fullPath),D(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;Rt()!==e&&(t?Ot(e):Ct(e))},e.prototype.getCurrentLocation=function(){return Rt()},e}(te),ne=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(){e.index=r,e.updateRoute(n)})}},e.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},e.prototype.ensureURL=function(){},e}(te),oe=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=V(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!Yt&&!1!==t.fallback,this.fallback&&(e="hash"),zt||(e="abstract"),this.mode=e,e){case"history":this.history=new ee(this,t.base);break;case"hash":this.history=new re(this,t.base,this.fallback);break;case"abstract":this.history=new ne(this,t.base)}},ie={currentRoute:{configurable:!0}};return oe.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},ie.currentRoute.get=function(){return this.history&&this.history.current},oe.prototype.init=function(t){var e=this;if(this.apps.push(t),!this.app){this.app=t;var r=this.history;if(r instanceof ee)r.transitionTo(r.getCurrentLocation());else if(r instanceof re){var n=function(){r.setupListeners()};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen(function(t){e.apps.forEach(function(e){e._route=t})})}},oe.prototype.beforeEach=function(t){return jt(this.beforeHooks,t)},oe.prototype.beforeResolve=function(t){return jt(this.resolveHooks,t)},oe.prototype.afterEach=function(t){return jt(this.afterHooks,t)},oe.prototype.onReady=function(t,e){this.history.onReady(t,e)},oe.prototype.onError=function(t){this.history.onError(t)},oe.prototype.push=function(t,e,r){this.history.push(t,e,r)},oe.prototype.replace=function(t,e,r){this.history.replace(t,e,r)},oe.prototype.go=function(t){this.history.go(t)},oe.prototype.back=function(){this.go(-1)},oe.prototype.forward=function(){this.go(1)},oe.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]})})):[]},oe.prototype.resolve=function(t,e,r){var n=H(t,e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:At(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},oe.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==Mt&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(oe.prototype,ie),oe.install=v,oe.version="3.0.0",zt&&window.Vue&&window.Vue.use(oe),oe}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e){}function e(t){return Object.prototype.toString.call(t).indexOf("Error")>-1}function r(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}}function n(t,e){for(var r in e)t[r]=e[r];return t}function o(t,e,r){void 0===e&&(e={});var n,o=r||i;try{n=o(t||"")}catch(t){n={}}for(var a in e)n[a]=e[a];return n}function i(t){var e={};return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var r=t.replace(/\+/g," ").split("="),n=Ut(r.shift()),o=r.length>0?Ut(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 a(t){var e=t?Object.keys(t).map(function(e){var r=t[e];if(void 0===r)return"";if(null===r)return Pt(e);if(Array.isArray(r)){var n=[];return r.forEach(function(t){void 0!==t&&(null===t?n.push(Pt(e)):n.push(Pt(e)+"="+Pt(t)))}),n.join("&")}return Pt(e)+"="+Pt(r)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function u(t,e,r,n){var o=n&&n.options.stringifyQuery,i=e.query||{};try{i=c(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:p(e,o),matched:t?s(t):[]};return r&&(a.redirectedFrom=p(r,o)),Object.freeze(a)}function c(t){if(Array.isArray(t))return t.map(c);if(t&&"object"==typeof t){var e={};for(var r in t)e[r]=c(t[r]);return e}return t}function s(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function p(t,e){var r=t.path,n=t.query;void 0===n&&(n={});var o=t.hash;void 0===o&&(o="");var i=e||a;return(r||"/")+i(n)+o}function f(t,e){return e===Ht?t===e:!!e&&(t.path&&e.path?t.path.replace(Mt,"")===e.path.replace(Mt,"")&&t.hash===e.hash&&h(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&h(t.query,e.query)&&h(t.params,e.params)))}function h(t,e){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"object"==typeof n&&"object"==typeof o?h(n,o):String(n)===String(o)})}function l(t,e){return 0===t.path.replace(Mt,"/").indexOf(e.path.replace(Mt,"/"))&&(!e.hash||t.hash===e.hash)&&d(t.query,e.query)}function d(t,e){for(var r in e)if(!(r in t))return!1;return!0}function y(t){if(!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||t.defaultPrevented||void 0!==t.button&&0!==t.button)){if(t.currentTarget&&t.currentTarget.getAttribute){var e=t.currentTarget.getAttribute("target");if(/\b_blank\b/i.test(e))return}return t.preventDefault&&t.preventDefault(),!0}}function v(t){if(t)for(var e,r=0;r=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}}function w(t){return t.replace(/\/\//g,"/")}function x(t,e){for(var r,n=[],o=0,i=0,a="",u=e&&e.delimiter||"/";null!=(r=Qt.exec(t));){var c=r[0],s=r[1],p=r.index;if(a+=t.slice(i,p),i=p+c.length,s)a+=s[1];else{var f=t[i],h=r[2],l=r[3],d=r[4],y=r[5],v=r[6],m=r[7];a&&(n.push(a),a="");var g=null!=h&&null!=f&&f!==h,b="+"===v||"*"===v,w="?"===v||"*"===v,x=r[2]||u,k=d||y;n.push({name:l||o++,prefix:h||"",delimiter:x,optional:w,repeat:b,partial:g,asterisk:!!m,pattern:k?C(k):m?".*":"[^"+O(x)+"]+?"})}}return i-1&&(o.params[h]=r.params[h]);if(u)return o.path=L(u.path,o.params,'named route "'+a+'"'),i(u,o,n)}else if(o.path){o.params={};for(var l=0;l=t.length?r():t[o]?e(t[o],function(){n(o+1)}):n(o+1)};n(0)}function at(t){return function(r,n,o){var i=!1,a=0,u=null;ut(t,function(t,r,n,c){if("function"==typeof t&&void 0===t.cid){i=!0,a++;var s,p=pt(function(e){st(e)&&(e=e.default),t.resolved="function"==typeof e?e:Tt.extend(e),n.components[c]=e,--a<=0&&o()}),f=pt(function(t){var r="Failed to resolve async component "+c+": "+t;u||(u=e(t)?t:new Error(r),o(u))});try{s=t(p,f)}catch(t){f(t)}if(s)if("function"==typeof s.then)s.then(p,f);else{var h=s.component;h&&"function"==typeof h.then&&h.then(p,f)}}}),i||o()}}function ut(t,e){return ct(t.map(function(t){return Object.keys(t.components).map(function(r){return e(t.components[r],t.instances[r],t,r)})}))}function ct(t){return Array.prototype.concat.apply([],t)}function st(t){return t.__esModule||te&&"Module"===t[Symbol.toStringTag]}function pt(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)}}function ft(t){if(!t)if(Bt){var e=document.querySelector("base");t=(t=e&&e.getAttribute("href")||"/").replace(/^https?:\/\/[^\/]+/,"")}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function ht(t,e){var r,n=Math.max(t.length,e.length);for(r=0;r=0?e.slice(0,r):e)+"#"+t}function Ct(t){Wt?nt(Ot(t)):window.location.hash=t}function jt(t){Wt?ot(Ot(t)):window.location.replace(Ot(t))}function At(t,e){return t.push(e),function(){var r=t.indexOf(e);r>-1&&t.splice(r,1)}}function _t(t,e,r){var n="hash"===r?"#"+e:e;return t?w(t+"/"+n):n}var Tt,St={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var o=e.props,i=e.children,a=e.parent,u=e.data;u.routerView=!0;for(var c=a.$createElement,s=o.name,p=a.$route,f=a._routerViewCache||(a._routerViewCache={}),h=0,l=!1;a&&a._routerRoot!==a;)a.$vnode&&a.$vnode.data.routerView&&h++,a._inactive&&(l=!0),a=a.$parent;if(u.routerViewDepth=h,l)return c(f[s],u,i);var d=p.matched[h];if(!d)return f[s]=null,c();var y=f[s]=d.components[s];u.registerRouteInstance=function(t,e){var r=d.instances[s];(e&&r!==t||!e&&r===t)&&(d.instances[s]=e)},(u.hook||(u.hook={})).prepatch=function(t,e){d.instances[s]=e.componentInstance};var v=u.props=r(p,d.props&&d.props[s]);if(v){v=u.props=n({},v);var m=u.attrs=u.attrs||{};for(var g in v)y.props&&g in y.props||(m[g]=v[g],delete v[g])}return c(y,u,i)}},$t=/[!'()*]/g,qt=function(t){return"%"+t.charCodeAt(0).toString(16)},Lt=/%2C/g,Pt=function(t){return encodeURIComponent(t).replace($t,qt).replace(Lt,",")},Ut=decodeURIComponent,Mt=/\/?$/,Ht=u(null,{path:"/"}),It=[String,Object],Vt=[String,Array],zt={name:"router-link",props:{to:{type:It,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String,exactActiveClass:String,event:{type:Vt,default:"click"}},render:function(t){var e=this,r=this.$router,n=this.$route,o=r.resolve(this.to,n,this.append),i=o.location,a=o.route,c=o.href,s={},p=r.options.linkActiveClass,h=r.options.linkExactActiveClass,d=null==p?"router-link-active":p,m=null==h?"router-link-exact-active":h,g=null==this.activeClass?d:this.activeClass,b=null==this.exactActiveClass?m:this.exactActiveClass,w=i.path?u(null,i,null,r):a;s[b]=f(n,w),s[g]=this.exact?s[b]:l(n,w);var x=function(t){y(t)&&(e.replace?r.replace(i):r.push(i))},k={click:y};Array.isArray(this.event)?this.event.forEach(function(t){k[t]=x}):k[this.event]=x;var R={class:s};if("a"===this.tag)R.on=k,R.attrs={href:c};else{var E=v(this.$slots.default);if(E){E.isStatic=!1;var O=Tt.util.extend;(E.data=O({},E.data)).on=k,(E.data.attrs=O({},E.data.attrs)).href=c}else R.on=k}return t(this.tag,R,this.$slots.default)}},Bt="undefined"!=typeof window,Ft=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},Dt=q,Kt=x,Jt=E,Nt=$,Qt=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");Dt.parse=Kt,Dt.compile=function(t,e){return E(x(t,e))},Dt.tokensToFunction=Jt,Dt.tokensToRegExp=Nt;var Xt=Object.create(null),Yt=Object.create(null),Wt=Bt&&function(){var 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&&"pushState"in window.history)}(),Gt=Bt&&window.performance&&window.performance.now?window.performance:Date,Zt=tt(),te="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,ee=function(t,e){this.router=t,this.base=ft(e),this.current=Ht,this.pending=null,this.ready=!1,this.readyCbs=[],this.readyErrorCbs=[],this.errorCbs=[]};ee.prototype.listen=function(t){this.cb=t},ee.prototype.onReady=function(t,e){this.ready?t():(this.readyCbs.push(t),e&&this.readyErrorCbs.push(e))},ee.prototype.onError=function(t){this.errorCbs.push(t)},ee.prototype.transitionTo=function(t,e,r){var n=this,o=this.router.match(t,this.current);this.confirmTransition(o,function(){n.updateRoute(o),e&&e(o),n.ensureURL(),n.ready||(n.ready=!0,n.readyCbs.forEach(function(t){t(o)}))},function(t){r&&r(t),t&&!n.ready&&(n.ready=!0,n.readyErrorCbs.forEach(function(e){e(t)}))})},ee.prototype.confirmTransition=function(r,n,o){var i=this,a=this.current,u=function(r){e(r)&&(i.errorCbs.length?i.errorCbs.forEach(function(t){t(r)}):(t(!1,"uncaught error during route navigation:"),console.error(r))),o&&o(r)};if(f(r,a)&&r.matched.length===a.matched.length)return this.ensureURL(),u();var c=ht(this.current.matched,r.matched),s=c.updated,p=c.deactivated,h=c.activated,l=[].concat(yt(p),this.router.beforeHooks,vt(s),h.map(function(t){return t.beforeEnter}),at(h));this.pending=r;var d=function(t,n){if(i.pending!==r)return u();try{t(r,a,function(t){!1===t||e(t)?(i.ensureURL(!0),u(t)):"string"==typeof t||"object"==typeof t&&("string"==typeof t.path||"string"==typeof t.name)?(u(),"object"==typeof t&&t.replace?i.replace(t):i.push(t)):n(t)})}catch(t){u(t)}};it(l,d,function(){var t=[];it(gt(h,t,function(){return i.current===r}).concat(i.router.resolveHooks),d,function(){if(i.pending!==r)return u();i.pending=null,n(r),i.router.app&&i.router.app.$nextTick(function(){t.forEach(function(t){t()})})})})},ee.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(r){r&&r(t,e)})};var re=function(t){function e(e,r){var n=this;t.call(this,e,r);var o=e.options.scrollBehavior;o&&D();var i=xt(this.base);window.addEventListener("popstate",function(t){var r=n.current,a=xt(n.base);n.current===Ht&&a===i||n.transitionTo(a,function(t){o&&K(e,t,r,!0)})})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){nt(w(n.base+t.fullPath)),K(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){ot(w(n.base+t.fullPath)),K(n.router,t,o,!1),e&&e(t)},r)},e.prototype.ensureURL=function(t){if(xt(this.base)!==this.current.fullPath){var e=w(this.base+this.current.fullPath);t?nt(e):ot(e)}},e.prototype.getCurrentLocation=function(){return xt(this.base)},e}(ee),ne=function(t){function e(e,r,n){t.call(this,e,r),n&&kt(this.base)||Rt()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setupListeners=function(){var t=this,e=this.router.options.scrollBehavior,r=Wt&&e;r&&D(),window.addEventListener(Wt?"popstate":"hashchange",function(){var e=t.current;Rt()&&t.transitionTo(Et(),function(n){r&&K(t.router,n,e,!0),Wt||jt(n.fullPath)})})},e.prototype.push=function(t,e,r){var n=this,o=this.current;this.transitionTo(t,function(t){Ct(t.fullPath),K(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){jt(t.fullPath),K(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;Et()!==e&&(t?Ct(e):jt(e))},e.prototype.getCurrentLocation=function(){return Et()},e}(ee),oe=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(){e.index=r,e.updateRoute(n)})}},e.prototype.getCurrentLocation=function(){var t=this.stack[this.stack.length-1];return t?t.fullPath:"/"},e.prototype.ensureURL=function(){},e}(ee),ie=function(t){void 0===t&&(t={}),this.app=null,this.apps=[],this.options=t,this.beforeHooks=[],this.resolveHooks=[],this.afterHooks=[],this.matcher=z(t.routes||[],this);var e=t.mode||"hash";switch(this.fallback="history"===e&&!Wt&&!1!==t.fallback,this.fallback&&(e="hash"),Bt||(e="abstract"),this.mode=e,e){case"history":this.history=new re(this,t.base);break;case"hash":this.history=new ne(this,t.base,this.fallback);break;case"abstract":this.history=new oe(this,t.base)}},ae={currentRoute:{configurable:!0}};return ie.prototype.match=function(t,e,r){return this.matcher.match(t,e,r)},ae.currentRoute.get=function(){return this.history&&this.history.current},ie.prototype.init=function(t){var e=this;if(this.apps.push(t),!this.app){this.app=t;var r=this.history;if(r instanceof re)r.transitionTo(r.getCurrentLocation());else if(r instanceof ne){var n=function(){r.setupListeners()};r.transitionTo(r.getCurrentLocation(),n,n)}r.listen(function(t){e.apps.forEach(function(e){e._route=t})})}},ie.prototype.beforeEach=function(t){return At(this.beforeHooks,t)},ie.prototype.beforeResolve=function(t){return At(this.resolveHooks,t)},ie.prototype.afterEach=function(t){return At(this.afterHooks,t)},ie.prototype.onReady=function(t,e){this.history.onReady(t,e)},ie.prototype.onError=function(t){this.history.onError(t)},ie.prototype.push=function(t,e,r){this.history.push(t,e,r)},ie.prototype.replace=function(t,e,r){this.history.replace(t,e,r)},ie.prototype.go=function(t){this.history.go(t)},ie.prototype.back=function(){this.go(-1)},ie.prototype.forward=function(){this.go(1)},ie.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]})})):[]},ie.prototype.resolve=function(t,e,r){var n=I(t,e||this.history.current,r,this),o=this.match(n,e),i=o.redirectedFrom||o.fullPath;return{location:n,route:o,href:_t(this.history.base,i,this.mode),normalizedTo:n,resolved:o}},ie.prototype.addRoutes=function(t){this.matcher.addRoutes(t),this.history.current!==Ht&&this.history.transitionTo(this.history.getCurrentLocation())},Object.defineProperties(ie.prototype,ae),ie.install=m,ie.version="3.0.1",Bt&&window.Vue&&window.Vue.use(ie),ie}); \ No newline at end of file From 90cd2690d59c6bd56e5bc12b5b752166a1d35e98 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 13 Oct 2017 12:24:06 -0400 Subject: [PATCH 9/9] [release] 3.0.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5aef0579a..1daad4257 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vue-router", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index be9c6d26c..3f15edcff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-router", - "version": "3.0.0", + "version": "3.0.1", "description": "Official router for Vue.js 2", "author": "Evan You", "license": "MIT",