vue-router
Advanced tools
Comparing version 2.0.0-rc.5 to 2.0.0-rc.6
/** | ||
* vue-router v2.0.0-rc.5 | ||
* vue-router v2.0.0-rc.6 | ||
* (c) 2016 Evan You | ||
@@ -7,5 +7,5 @@ * @license MIT | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.VueRouter = factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.VueRouter = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -65,9 +65,9 @@ | ||
/* */ | ||
/* */ | ||
function resolvePath ( | ||
relative , | ||
base , | ||
append | ||
) { | ||
relative, | ||
base, | ||
append | ||
) { | ||
if (relative.charAt(0) === '/') { | ||
@@ -111,7 +111,3 @@ return relative | ||
function parsePath (path ) | ||
{ | ||
function parsePath (path) { | ||
var hash = '' | ||
@@ -139,9 +135,9 @@ var query = '' | ||
function cleanPath (path ) { | ||
function cleanPath (path) { | ||
return path.replace(/\/\//g, '/') | ||
} | ||
/* */ | ||
/* */ | ||
function assert (condition , message ) { | ||
function assert (condition, message) { | ||
if (!condition) { | ||
@@ -152,3 +148,3 @@ throw new Error(("[vue-router] " + message)) | ||
function warn (condition , message ) { | ||
function warn (condition, message) { | ||
if (!condition) { | ||
@@ -159,3 +155,3 @@ typeof console !== 'undefined' && console.warn(("[vue-router] " + message)) | ||
/* */ | ||
/* */ | ||
@@ -166,6 +162,6 @@ var encode = encodeURIComponent | ||
function resolveQuery ( | ||
query , | ||
query, | ||
extraQuery | ||
) { | ||
if ( extraQuery === void 0 ) extraQuery = {}; | ||
) { | ||
if ( extraQuery === void 0 ) extraQuery = {}; | ||
@@ -189,3 +185,3 @@ if (query) { | ||
function parseQuery (query ) { | ||
function parseQuery (query) { | ||
var res = Object.create(null) | ||
@@ -218,3 +214,3 @@ | ||
function stringifyQuery (obj ) { | ||
function stringifyQuery (obj) { | ||
var res = obj ? Object.keys(obj).sort().map(function (key) { | ||
@@ -251,10 +247,10 @@ var val = obj[key] | ||
/* */ | ||
/* */ | ||
function createRoute ( | ||
record , | ||
location , | ||
redirectedFrom | ||
) { | ||
var route = { | ||
record, | ||
location, | ||
redirectedFrom | ||
) { | ||
var route = { | ||
name: location.name || (record && record.name), | ||
@@ -275,3 +271,8 @@ meta: (record && record.meta) || {}, | ||
function formatMatch (record ) { | ||
// the starting route that represents the initial state | ||
var START = createRoute(null, { | ||
path: '/' | ||
}) | ||
function formatMatch (record) { | ||
var res = [] | ||
@@ -294,4 +295,6 @@ while (record) { | ||
var trailingSlashRE = /\/$/ | ||
function isSameRoute (a , b ) { | ||
if (!b) { | ||
function isSameRoute (a, b) { | ||
if (b === START) { | ||
return a === b | ||
} else if (!b) { | ||
return false | ||
@@ -316,3 +319,3 @@ } else if (a.path && b.path) { | ||
function isObjectEqual (a, b) { | ||
function isObjectEqual (a, b) { | ||
if ( a === void 0 ) a = {}; | ||
@@ -329,3 +332,3 @@ if ( b === void 0 ) b = {}; | ||
function isIncludedRoute (current , target ) { | ||
function isIncludedRoute (current, target) { | ||
return ( | ||
@@ -338,3 +341,3 @@ current.path.indexOf(target.path) === 0 && | ||
function queryIncludes (current , target ) { | ||
function queryIncludes (current, target) { | ||
for (var key in target) { | ||
@@ -348,10 +351,10 @@ if (!(key in current)) { | ||
/* */ | ||
/* */ | ||
function normalizeLocation ( | ||
raw , | ||
current , | ||
append | ||
) { | ||
var next = typeof raw === 'string' ? { path: raw } : raw | ||
raw, | ||
current, | ||
append | ||
) { | ||
var next = typeof raw === 'string' ? { path: raw } : raw | ||
if (next.name || next._normalized) { | ||
@@ -380,6 +383,6 @@ return next | ||
/* */ | ||
/* */ | ||
// work around weird flow bug | ||
var toTypes = [String, Object] | ||
var toTypes = [String, Object] | ||
@@ -402,3 +405,3 @@ var Link = { | ||
}, | ||
render: function render (h ) { | ||
render: function render (h) { | ||
var this$1 = this; | ||
@@ -420,12 +423,9 @@ | ||
var data = { | ||
class: classes, | ||
on: { | ||
click: function (e) { | ||
e.preventDefault() | ||
if (this$1.replace) { | ||
router.replace(to) | ||
} else { | ||
router.push(to) | ||
} | ||
var on = { | ||
click: function (e) { | ||
e.preventDefault() | ||
if (this$1.replace) { | ||
router.replace(to) | ||
} else { | ||
router.push(to) | ||
} | ||
@@ -435,9 +435,15 @@ } | ||
var data = { | ||
class: classes | ||
} | ||
if (this.tag === 'a') { | ||
data.on = on | ||
data.attrs = { href: href } | ||
} else { | ||
// find the first <a> child and apply href | ||
// find the first <a> child and apply listener and href | ||
var a = findAnchor(this.$slots.default) | ||
if (a) { | ||
var aData = a.data || (a.data = {}) | ||
aData.on = on | ||
var aAttrs = aData.attrs || (aData.attrs = {}) | ||
@@ -468,3 +474,3 @@ aAttrs.href = href | ||
function install (Vue) { | ||
if (install.installed) return | ||
if (install.installed) { return } | ||
install.installed = true | ||
@@ -494,34 +500,16 @@ | ||
function interopDefault(ex) { | ||
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var index$1 = createCommonjsModule(function (module) { | ||
module.exports = Array.isArray || function (arr) { | ||
var __moduleExports = Array.isArray || function (arr) { | ||
return Object.prototype.toString.call(arr) == '[object Array]'; | ||
}; | ||
}); | ||
var index$2 = interopDefault(index$1); | ||
var isarray = __moduleExports | ||
var require$$0 = Object.freeze({ | ||
default: index$2 | ||
}); | ||
var index = createCommonjsModule(function (module) { | ||
var isarray = interopDefault(require$$0) | ||
/** | ||
* Expose `pathToRegexp`. | ||
*/ | ||
module.exports = pathToRegexp | ||
module.exports.parse = parse | ||
module.exports.compile = compile | ||
module.exports.tokensToFunction = tokensToFunction | ||
module.exports.tokensToRegExp = tokensToRegExp | ||
var index = pathToRegexp | ||
var parse_1 = parse | ||
var compile_1 = compile | ||
var tokensToFunction_1 = tokensToFunction | ||
var tokensToRegExp_1 = tokensToRegExp | ||
@@ -943,14 +931,13 @@ /** | ||
} | ||
}); | ||
var Regexp = interopDefault(index); | ||
index.parse = parse_1; | ||
index.compile = compile_1; | ||
index.tokensToFunction = tokensToFunction_1; | ||
index.tokensToRegExp = tokensToRegExp_1; | ||
/* */ | ||
/* */ | ||
function createRouteMap (routes ) | ||
{ | ||
var pathMap = Object.create(null) | ||
var nameMap = Object.create(null) | ||
function createRouteMap (routes) { | ||
var pathMap = Object.create(null) | ||
var nameMap = Object.create(null) | ||
@@ -968,7 +955,7 @@ routes.forEach(function (route) { | ||
function addRouteRecord ( | ||
pathMap , | ||
nameMap , | ||
route , | ||
parent , | ||
matchAs | ||
pathMap, | ||
nameMap, | ||
route, | ||
parent, | ||
matchAs | ||
) { | ||
@@ -979,3 +966,3 @@ var path = route.path; | ||
var record = { | ||
var record = { | ||
path: normalizePath(path, parent), | ||
@@ -1013,26 +1000,19 @@ components: route.components || { default: route.component }, | ||
pathMap[record.path] = record | ||
if (name) nameMap[name] = record | ||
if (name) { nameMap[name] = record } | ||
} | ||
function normalizePath (path , parent ) { | ||
function normalizePath (path, parent) { | ||
path = path.replace(/\/$/, '') | ||
if (path[0] === '/') return path | ||
if (parent == null) return path | ||
if (path[0] === '/') { return path } | ||
if (parent == null) { return path } | ||
return cleanPath(((parent.path) + "/" + path)) | ||
} | ||
/* */ | ||
/* */ | ||
var regexpCache | ||
= Object.create(null) | ||
var regexpCache = Object.create(null) | ||
var regexpCompileCache | ||
= Object.create(null) | ||
var regexpCompileCache = Object.create(null) | ||
function createMatcher (routes ) { | ||
function createMatcher (routes) { | ||
var ref = createRouteMap(routes); | ||
@@ -1043,6 +1023,6 @@ var pathMap = ref.pathMap; | ||
function match ( | ||
raw , | ||
currentRoute , | ||
redirectedFrom | ||
) { | ||
raw, | ||
currentRoute, | ||
redirectedFrom | ||
) { | ||
var location = normalizeLocation(raw, currentRoute) | ||
@@ -1070,5 +1050,5 @@ var name = location.name; | ||
function redirect ( | ||
record , | ||
location | ||
) { | ||
record, | ||
location | ||
) { | ||
var originalRedirect = record.redirect | ||
@@ -1088,3 +1068,3 @@ var redirect = typeof originalRedirect === 'function' | ||
var re = redirect | ||
var re = redirect | ||
var name = re.name; | ||
@@ -1129,6 +1109,6 @@ var path = re.path; | ||
function alias ( | ||
record , | ||
location , | ||
matchAs | ||
) { | ||
record, | ||
location, | ||
matchAs | ||
) { | ||
var aliasedPath = fillParams(matchAs, location.params, ("aliased route with path \"" + matchAs + "\"")) | ||
@@ -1149,6 +1129,6 @@ var aliasedMatch = match({ | ||
function _createRoute ( | ||
record , | ||
location , | ||
redirectedFrom | ||
) { | ||
record, | ||
location, | ||
redirectedFrom | ||
) { | ||
if (record && record.redirect) { | ||
@@ -1167,6 +1147,6 @@ return redirect(record, redirectedFrom || location) | ||
function matchRoute ( | ||
path , | ||
params , | ||
pathname | ||
) { | ||
path, | ||
params, | ||
pathname | ||
) { | ||
var keys, regexp | ||
@@ -1179,3 +1159,3 @@ var hit = regexpCache[path] | ||
keys = [] | ||
regexp = Regexp(path, keys) | ||
regexp = index(path, keys) | ||
regexpCache[path] = { keys: keys, regexp: regexp } | ||
@@ -1194,3 +1174,3 @@ } | ||
var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i] | ||
if (key) params[key.name] = val | ||
if (key) { params[key.name] = val } | ||
} | ||
@@ -1202,10 +1182,10 @@ | ||
function fillParams ( | ||
path , | ||
params , | ||
routeMsg | ||
) { | ||
path, | ||
params, | ||
routeMsg | ||
) { | ||
try { | ||
var filler = | ||
regexpCompileCache[path] || | ||
(regexpCompileCache[path] = Regexp.compile(path)) | ||
(regexpCompileCache[path] = index.compile(path)) | ||
return filler(params || {}, { pretty: true }) | ||
@@ -1218,7 +1198,7 @@ } catch (e) { | ||
function resolveRecordPath (path , record ) { | ||
function resolveRecordPath (path, record) { | ||
return resolvePath(path, record.parent ? record.parent.path : '/', true) | ||
} | ||
/* */ | ||
/* */ | ||
@@ -1242,5 +1222,5 @@ var inBrowser = typeof window !== 'undefined' | ||
/* */ | ||
/* */ | ||
function runQueue (queue , fn , cb ) { | ||
function runQueue (queue, fn, cb) { | ||
var step = function (index) { | ||
@@ -1262,20 +1242,18 @@ if (index >= queue.length) { | ||
/* */ | ||
/* */ | ||
var History = function History (router , base ) { | ||
var History = function History (router, base) { | ||
this.router = router | ||
this.base = normalizeBase(base) | ||
// start with a route object that stands for "nowhere" | ||
this.current = createRoute(null, { | ||
path: '__vue_router_init__' | ||
}) | ||
this.current = START | ||
this.pending = null | ||
}; | ||
History.prototype.listen = function listen (cb ) { | ||
History.prototype.listen = function listen (cb) { | ||
this.cb = cb | ||
}; | ||
History.prototype.transitionTo = function transitionTo (location , cb ) { | ||
History.prototype.transitionTo = function transitionTo (location, cb) { | ||
var this$1 = this; | ||
@@ -1287,9 +1265,12 @@ | ||
cb && cb(route) | ||
this$1.ensureURL() | ||
}) | ||
}; | ||
History.prototype.confirmTransition = function confirmTransition (route , cb ) { | ||
History.prototype.confirmTransition = function confirmTransition (route, cb) { | ||
var this$1 = this; | ||
if (isSameRoute(route, this.current)) { | ||
var current = this.current | ||
if (isSameRoute(route, current)) { | ||
this.ensureURL() | ||
return | ||
@@ -1314,4 +1295,17 @@ } | ||
this.pending = route | ||
var redirect = function (location) { return this$1.push(location); } | ||
var iterator = function (hook, next) { return hook(route, redirect, next); } | ||
var iterator = function (hook, next) { | ||
if (this$1.pending !== route) { return } | ||
hook(route, current, function (to) { | ||
if (to === false) { | ||
// next(false) -> abort navigation, ensure current URL | ||
this$1.ensureURL() | ||
} else if (typeof to === 'string' || typeof to === 'object') { | ||
// next('/') or next({ path: '/' }) -> redirect | ||
this$1.push(to) | ||
} else { | ||
// confirm transition and pass on the value | ||
next(to) | ||
} | ||
}) | ||
} | ||
@@ -1323,3 +1317,3 @@ runQueue(queue, iterator, function () { | ||
runQueue(extractEnterGuards(activated, postEnterCbs), iterator, function () { | ||
if (isSameRoute(route, this$1.pending)) { | ||
if (this$1.pending === route) { | ||
this$1.pending = null | ||
@@ -1335,11 +1329,12 @@ cb(route) | ||
History.prototype.updateRoute = function updateRoute (route ) { | ||
History.prototype.updateRoute = function updateRoute (route) { | ||
var prev = this.current | ||
this.current = route | ||
this.cb && this.cb(route) | ||
this.router.afterHooks.forEach(function (hook) { | ||
hook && hook(route) | ||
hook && hook(route, prev) | ||
}) | ||
}; | ||
function normalizeBase (base ) { | ||
function normalizeBase (base) { | ||
if (!base) { | ||
@@ -1363,8 +1358,5 @@ if (inBrowser) { | ||
function resolveQueue ( | ||
current , | ||
next | ||
) | ||
{ | ||
current, | ||
next | ||
) { | ||
var i | ||
@@ -1383,3 +1375,3 @@ var max = Math.max(current.length, next.length) | ||
function extractLeaveGuards (matched ) { | ||
function extractLeaveGuards (matched) { | ||
return flatMapComponents(matched, function (def, instance) { | ||
@@ -1395,12 +1387,14 @@ var guard = def && def.beforeRouteLeave | ||
function extractEnterGuards (matched , cbs ) { | ||
function extractEnterGuards (matched, cbs) { | ||
return flatMapComponents(matched, function (def, _, match, key) { | ||
var guard = def && def.beforeRouteEnter | ||
if (guard) { | ||
return function routeEnterGuard (route, redirect, next) { | ||
return guard(route, redirect, function (cb) { | ||
next() | ||
cb && cbs.push(function () { | ||
cb(match.instances[key]) | ||
}) | ||
return function routeEnterGuard (to, from, next) { | ||
return guard(to, from, function (cb) { | ||
next(cb) | ||
if (typeof cb === 'function') { | ||
cbs.push(function () { | ||
cb(match.instances[key]) | ||
}) | ||
} | ||
}) | ||
@@ -1412,3 +1406,3 @@ } | ||
function resolveAsyncComponents (matched ) { | ||
function resolveAsyncComponents (matched) { | ||
return flatMapComponents(matched, function (def, _, match, key) { | ||
@@ -1421,3 +1415,3 @@ // if it's a function and doesn't have Vue options attached, | ||
if (typeof def === 'function' && !def.options) { | ||
return function (route, redirect, next) { | ||
return function (to, from, next) { | ||
var resolve = function (resolvedDef) { | ||
@@ -1430,2 +1424,3 @@ match.components[key] = resolvedDef | ||
warn(false, ("Failed to resolve async component " + key + ": " + reason)) | ||
next(false) | ||
} | ||
@@ -1443,5 +1438,5 @@ | ||
function flatMapComponents ( | ||
matched , | ||
fn | ||
) { | ||
matched, | ||
fn | ||
) { | ||
return Array.prototype.concat.apply([], matched.map(function (m) { | ||
@@ -1456,6 +1451,6 @@ return Object.keys(m.components).map(function (key) { return fn( | ||
/* */ | ||
/* */ | ||
function saveScrollPosition (key ) { | ||
if (!key) return | ||
function saveScrollPosition (key) { | ||
if (!key) { return } | ||
window.sessionStorage.setItem(key, JSON.stringify({ | ||
@@ -1467,8 +1462,8 @@ x: window.pageXOffset, | ||
function getScrollPosition (key ) { | ||
if (!key) return | ||
function getScrollPosition (key) { | ||
if (!key) { return } | ||
return JSON.parse(window.sessionStorage.getItem(key)) | ||
} | ||
function getElementPosition (el ) { | ||
function getElementPosition (el) { | ||
var docRect = document.documentElement.getBoundingClientRect() | ||
@@ -1482,7 +1477,7 @@ var elRect = el.getBoundingClientRect() | ||
function isValidPosition (obj ) { | ||
function isValidPosition (obj) { | ||
return isNumber(obj.x) || isNumber(obj.y) | ||
} | ||
function normalizePosition (obj ) { | ||
function normalizePosition (obj) { | ||
return { | ||
@@ -1494,14 +1489,14 @@ x: isNumber(obj.x) ? obj.x : window.pageXOffset, | ||
function isNumber (v ) { | ||
function isNumber (v) { | ||
return typeof v === 'number' | ||
} | ||
/* */ | ||
/* */ | ||
var genKey = function () { return String(Date.now()); } | ||
var _key = genKey() | ||
var _key = genKey() | ||
var HTML5History = (function (History) { | ||
function HTML5History (router , base ) { | ||
function HTML5History (router, base) { | ||
var this$1 = this; | ||
@@ -1511,10 +1506,3 @@ | ||
var initialLocation = getLocation(this.base) | ||
this.transitionTo(initialLocation, function (route) { | ||
// possible redirect on start | ||
var url = cleanPath(this$1.base + this$1.current.fullPath) | ||
if (initialLocation !== url) { | ||
replaceState(url) | ||
} | ||
}) | ||
this.transitionTo(getLocation(this.base)) | ||
@@ -1543,11 +1531,11 @@ var expectScroll = router.options.scrollBehavior | ||
HTML5History.prototype.go = function go (n ) { | ||
HTML5History.prototype.go = function go (n) { | ||
window.history.go(n) | ||
}; | ||
HTML5History.prototype.push = function push (location ) { | ||
HTML5History.prototype.push = function push (location) { | ||
var this$1 = this; | ||
var current = this.current | ||
History.prototype.transitionTo.call(this, location, function (route) { | ||
this.transitionTo(location, function (route) { | ||
pushState(cleanPath(this$1.base + route.fullPath)) | ||
@@ -1558,7 +1546,7 @@ this$1.handleScroll(route, current, false) | ||
HTML5History.prototype.replace = function replace (location ) { | ||
HTML5History.prototype.replace = function replace (location) { | ||
var this$1 = this; | ||
var current = this.current | ||
History.prototype.transitionTo.call(this, location, function (route) { | ||
this.transitionTo(location, function (route) { | ||
replaceState(cleanPath(this$1.base + route.fullPath)) | ||
@@ -1569,3 +1557,9 @@ this$1.handleScroll(route, current, false) | ||
HTML5History.prototype.handleScroll = function handleScroll (to , from , isPop ) { | ||
HTML5History.prototype.ensureURL = function ensureURL () { | ||
if (getLocation(this.base) !== this.current.fullPath) { | ||
replaceState(cleanPath(this.base + this.current.fullPath)) | ||
} | ||
}; | ||
HTML5History.prototype.handleScroll = function handleScroll (to, from, isPop) { | ||
var router = this.router | ||
@@ -1590,3 +1584,3 @@ if (!router.app) { | ||
var isObject = typeof shouldScroll === 'object' | ||
if (isObject && shouldScroll.selector) { | ||
if (isObject && typeof shouldScroll.selector === 'string') { | ||
var el = document.querySelector(shouldScroll.selector) | ||
@@ -1611,3 +1605,3 @@ if (el) { | ||
function getLocation (base ) { | ||
function getLocation (base) { | ||
var path = window.location.pathname | ||
@@ -1620,3 +1614,3 @@ if (base && path.indexOf(base) === 0) { | ||
function pushState (url , replace ) { | ||
function pushState (url, replace) { | ||
// try...catch the pushState call to get around Safari | ||
@@ -1638,11 +1632,11 @@ // DOM Exception 18 where it limits to 100 pushState calls | ||
function replaceState (url ) { | ||
function replaceState (url) { | ||
pushState(url, true) | ||
} | ||
/* */ | ||
/* */ | ||
var HashHistory = (function (History) { | ||
function HashHistory (router , base , fallback ) { | ||
function HashHistory (router, base, fallback) { | ||
var this$1 = this; | ||
@@ -1658,8 +1652,3 @@ | ||
ensureSlash() | ||
this.transitionTo(getHash(), function (route) { | ||
// possible redirect on start | ||
if (getHash() !== route.fullPath) { | ||
replaceHash(route.fullPath) | ||
} | ||
}) | ||
this.transitionTo(getHash()) | ||
@@ -1685,2 +1674,8 @@ window.addEventListener('hashchange', function () { | ||
HashHistory.prototype.ensureURL = function ensureURL () { | ||
if (getHash() !== this.current.fullPath) { | ||
replaceHash(this.current.fullPath) | ||
} | ||
}; | ||
HashHistory.prototype.onHashChange = function onHashChange () { | ||
@@ -1695,3 +1690,3 @@ if (!ensureSlash()) { | ||
HashHistory.prototype.push = function push (location ) { | ||
HashHistory.prototype.push = function push (location) { | ||
History.prototype.transitionTo.call(this, location, function (route) { | ||
@@ -1702,3 +1697,3 @@ pushHash(route.fullPath) | ||
HashHistory.prototype.replace = function replace (location ) { | ||
HashHistory.prototype.replace = function replace (location) { | ||
History.prototype.transitionTo.call(this, location, function (route) { | ||
@@ -1709,3 +1704,3 @@ replaceHash(route.fullPath) | ||
HashHistory.prototype.go = function go (n ) { | ||
HashHistory.prototype.go = function go (n) { | ||
window.history.go(n) | ||
@@ -1717,3 +1712,3 @@ }; | ||
function ensureSlash () { | ||
function ensureSlash () { | ||
var path = getHash() | ||
@@ -1727,3 +1722,3 @@ if (path.charAt(0) === '/') { | ||
function getHash () { | ||
function getHash () { | ||
// We can't use window.location.hash here because it's not | ||
@@ -1747,7 +1742,7 @@ // consistent across browsers - Firefox will pre-decode it! | ||
/* */ | ||
/* */ | ||
var AbstractHistory = (function (History) { | ||
function AbstractHistory (router ) { | ||
function AbstractHistory (router) { | ||
History.call(this, router) | ||
@@ -1762,3 +1757,3 @@ this.stack = [] | ||
AbstractHistory.prototype.push = function push (location ) { | ||
AbstractHistory.prototype.push = function push (location) { | ||
var this$1 = this; | ||
@@ -1772,3 +1767,3 @@ | ||
AbstractHistory.prototype.replace = function replace (location ) { | ||
AbstractHistory.prototype.replace = function replace (location) { | ||
var this$1 = this; | ||
@@ -1781,3 +1776,3 @@ | ||
AbstractHistory.prototype.go = function go (n ) { | ||
AbstractHistory.prototype.go = function go (n) { | ||
var this$1 = this; | ||
@@ -1799,6 +1794,6 @@ | ||
/* */ | ||
/* */ | ||
var VueRouter = function VueRouter (options) { | ||
if ( options === void 0 ) options = {}; | ||
if ( options === void 0 ) options = {}; | ||
@@ -1824,7 +1819,7 @@ this.app = null | ||
prototypeAccessors.currentRoute.get = function () { | ||
prototypeAccessors.currentRoute.get = function () { | ||
return this.history && this.history.current | ||
}; | ||
VueRouter.prototype.init = function init (app /* Vue component instance */) { | ||
VueRouter.prototype.init = function init (app /* Vue component instance */) { | ||
var this$1 = this; | ||
@@ -1863,19 +1858,19 @@ | ||
VueRouter.prototype.beforeEach = function beforeEach (fn ) { | ||
VueRouter.prototype.beforeEach = function beforeEach (fn) { | ||
this.beforeHooks.push(fn) | ||
}; | ||
VueRouter.prototype.afterEach = function afterEach (fn ) { | ||
VueRouter.prototype.afterEach = function afterEach (fn) { | ||
this.afterHooks.push(fn) | ||
}; | ||
VueRouter.prototype.push = function push (location ) { | ||
VueRouter.prototype.push = function push (location) { | ||
this.history.push(location) | ||
}; | ||
VueRouter.prototype.replace = function replace (location ) { | ||
VueRouter.prototype.replace = function replace (location) { | ||
this.history.replace(location) | ||
}; | ||
VueRouter.prototype.go = function go (n ) { | ||
VueRouter.prototype.go = function go (n) { | ||
this.history.go(n) | ||
@@ -1892,3 +1887,3 @@ }; | ||
VueRouter.prototype.getMatchedComponents = function getMatchedComponents () { | ||
VueRouter.prototype.getMatchedComponents = function getMatchedComponents () { | ||
if (!this.currentRoute) { | ||
@@ -1895,0 +1890,0 @@ return [] |
/** | ||
* vue-router v2.0.0-rc.5 | ||
* vue-router v2.0.0-rc.6 | ||
* (c) 2016 Evan You | ||
* @license MIT | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if("/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i<o.length;i++){var a=o[i];"."!==a&&(".."===a?r.pop():r.push(a))}return""!==r[0]&&r.unshift(""),r.join("/")}function e(t){var e="",n="",r=t.indexOf("#");r>=0&&(e=t.slice(r),t=t.slice(0,r));var o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}function n(t){return t.replace(/\/\//g,"/")}function r(t,e){if(!t)throw new Error("[vue-router] "+e)}function o(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function i(t,e){if(void 0===e&&(e={}),t){var n;try{n=a(t)}catch(t){o(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function a(t){var e=Object.create(null);return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=W(n.shift()),o=n.length>0?W(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return Y(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(Y(e)):r.push(Y(e)+"="+Y(t)))}),r.join("&")}return Y(e)+"="+Y(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function c(t,e,n){var r={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:p(e),matched:t?s(t):[]};return n&&(r.redirectedFrom=p(n)),Object.freeze(r)}function s(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function p(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+u(n)+r}function f(t,e){return!!e&&(t.path&&e.path?t.path.replace(G,"")===e.path.replace(G,"")&&t.hash===e.hash&&h(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&h(t.query,e.query)&&h(t.params,e.params)))}function h(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function l(t,e){return 0===t.path.indexOf(e.path)&&(!e.hash||t.hash===e.hash)&&d(t.query,e.query)}function d(t,e){for(var n in e)if(!(n in t))return!1;return!0}function y(n,r,o){var a="string"==typeof n?{path:n}:n;if(a.name||a._normalized)return a;var u=e(a.path||""),c=r&&r.path||"/",s=u.path?t(u.path,c,o):r&&r.path||"/",p=i(u.query,a.query),f=a.hash||u.hash;return f&&"#"!==f.charAt(0)&&(f="#"+f),{_normalized:!0,path:s,query:p,hash:f}}function v(t){if(t)for(var e,n=0;n<t.length;n++){if(e=t[n],"a"===e.tag)return e;if(e.children&&(e=v(e.children)))return e}}function m(t){m.installed||(m.installed=!0,Object.defineProperty(t.prototype,"$router",{get:function(){return this.$root._router}}),Object.defineProperty(t.prototype,"$route",{get:function(){return this.$root._route}}),t.mixin({beforeCreate:function(){this.$options.router&&(this._router=this.$options.router,this._router.init(this),t.util.defineReactive(this,"_route",this._router.history.current))}}),t.component("router-view",X),t.component("router-link",Q))}function g(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function w(t,e){return e={exports:{}},t(e,e.exports),e.exports}function b(t){var e=Object.create(null),n=Object.create(null);return t.forEach(function(t){x(e,n,t)}),{pathMap:e,nameMap:n}}function x(t,e,n,o,i){var a=n.path,u=n.name;r(null!=a,'"path" is required in a route configuration.');var c={path:k(a,o),components:n.components||{default:n.component},instances:{},name:u,parent:o,matchAs:i,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{}};n.children&&n.children.forEach(function(n){x(t,e,n,c)}),n.alias&&(Array.isArray(n.alias)?n.alias.forEach(function(n){x(t,e,{path:n},o,c.path)}):x(t,e,{path:n.alias},o,c.path)),t[c.path]=c,u&&(e[u]=c)}function k(t,e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:n(e.path+"/"+t)}function O(t){function e(t,e,n){var r=y(t,e),o=r.name;if(o){var i=p[o];if(i)return r.path=_(i.path,r.params,'named route "'+o+'"'),a(i,r,n)}else if(r.path){r.params={};for(var u in s)if(E(u,r.params,r.path))return a(s[u],r,n)}return a(null,r)}function n(t,n){var i=t.redirect,u="function"==typeof i?i(c(t,n)):i;if("string"==typeof u&&(u={path:u}),!u||"object"!=typeof u)return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n);var s=u,f=s.name,h=s.path,l=n.query,d=n.hash,y=n.params;if(l=s.hasOwnProperty("query")?s.query:l,d=s.hasOwnProperty("hash")?s.hash:d,y=s.hasOwnProperty("params")?s.params:y,f){var v=p[f];return r(v,'redirect failed: named route "'+f+'" not found.'),e({_normalized:!0,name:f,query:l,hash:d,params:y},void 0,n)}if(h){var m=j(h,t),g=_(m,y,'redirect route with path "'+m+'"');return e({_normalized:!0,path:g,query:l,hash:d},void 0,n)}return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n)}function i(t,n,r){var o=_(r,n.params,'aliased route with path "'+r+'"'),i=e({_normalized:!0,path:o});if(i){var u=i.matched,c=u[u.length-1];return n.params=i.params,a(c,n)}return a(null,n)}function a(t,e,r){return t&&t.redirect?n(t,r||e):t&&t.matchAs?i(t,e,t.matchAs):c(t,e,r)}var u=b(t),s=u.pathMap,p=u.nameMap;return e}function E(t,e,n){var r,o,i=ot[t];i?(r=i.keys,o=i.regexp):(r=[],o=rt(t,r),ot[t]={keys:r,regexp:o});var a=n.match(o);if(!a)return!1;if(!e)return!0;for(var u=1,c=a.length;u<c;++u){var s=r[u-1],p="string"==typeof a[u]?decodeURIComponent(a[u]):a[u];s&&(e[s.name]=p)}return!0}function _(t,e,n){try{var o=it[t]||(it[t]=rt.compile(t));return o(e||{},{pretty:!0})}catch(t){return r(!1,"missing param for "+n+": "+t.message),""}}function j(e,n){return t(e,n.parent?n.parent.path:"/",!0)}function S(t,e,n){var r=function(o){o>=t.length?n():t[o]?e(t[o],function(){r(o+1)}):r(o+1)};r(0)}function $(t){if(!t)if(at){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function A(t,e){var n,r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{activated:e.slice(n),deactivated:t.slice(n)}}function R(t){return C(t,function(t,e){var n=t&&t.beforeRouteLeave;if(n)return function(){return n.apply(e,arguments)}}).reverse()}function T(t,e){return C(t,function(t,n,r,o){var i=t&&t.beforeRouteEnter;if(i)return function(t,n,a){return i(t,n,function(t){a(),t&&e.push(function(){t(r.instances[o])})})}})}function q(t){return C(t,function(t,e,n,r){if("function"==typeof t&&!t.options)return function(e,i,a){var u=function(t){n.components[r]=t,a()},c=function(t){o(!1,"Failed to resolve async component "+r+": "+t)},s=t(u,c);s&&"function"==typeof s.then&&s.then(u,c)}})}function C(t,e){return Array.prototype.concat.apply([],t.map(function(t){return Object.keys(t.components).map(function(n){return e(t.components[n],t.instances[n],t,n)})}))}function P(t){t&&window.sessionStorage.setItem(t,JSON.stringify({x:window.pageXOffset,y:window.pageYOffset}))}function V(t){if(t)return JSON.parse(window.sessionStorage.getItem(t))}function B(t){var e=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top}}function H(t){return M(t.x)||M(t.y)}function I(t){return{x:M(t.x)?t.x:window.pageXOffset,y:M(t.y)?t.y:window.pageYOffset}}function M(t){return"number"==typeof t}function U(t){var e=window.location.pathname;return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}function z(t,e){var n=window.history;try{e?n.replaceState({key:pt},"",t):(pt=st(),n.pushState({key:pt},"",t)),P(pt)}catch(n){window.location[e?"assign":"replace"](t)}}function F(t){z(t,!0)}function J(){var t=N();return"/"===t.charAt(0)||(D("/"+t),!1)}function N(){var t=window.location.href,e=t.indexOf("#");return e===-1?"":t.slice(e+1)}function L(t){window.location.hash=t}function D(t){var e=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,e>=0?e:0)+"#"+t)}var X={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,u=o._routerViewCache||(o._routerViewCache={}),c=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&c++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=c;var p=a.matched[c];if(!p)return t();var f=s?u[n.name]:u[n.name]=p.components[n.name];return s||((i.hook||(i.hook={})).init=function(t){p.instances[n.name]=t.child}),t(f,i,r)}},Y=encodeURIComponent,W=decodeURIComponent,G=/\/$/,K=[String,Object],Q={name:"router-link",props:{to:{type:K,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,r=this.$router,o=this.$route,i=y(this.to,o,this.append),a=r.match(i),u=a.redirectedFrom||a.fullPath,s=r.history.base,p=s?n(s+u):u,h={},d=this.activeClass||r.options.linkActiveClass||"router-link-active",m=i.path?c(null,i):a;h[d]=this.exact?f(o,m):l(o,m);var g={class:h,on:{click:function(t){t.preventDefault(),e.replace?r.replace(i):r.push(i)}}};if("a"===this.tag)g.attrs={href:p};else{var w=v(this.$slots.default);if(w){var b=w.data||(w.data={}),x=b.attrs||(b.attrs={});x.href=p}}return t(this.tag,g,this.$slots.default)}},Z=w(function(t){t.exports=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)}}),tt=g(Z),et=Object.freeze({default:tt}),nt=w(function(t){function e(t){for(var e,n=[],r=0,o=0,i="";null!=(e=v.exec(t));){var a=e[0],c=e[1],s=e.index;if(i+=t.slice(o,s),o=s+a.length,c)i+=c[1];else{var p=t[o],f=e[2],h=e[3],l=e[4],d=e[5],y=e[6],m=e[7];i&&(n.push(i),i="");var g=null!=f&&null!=p&&p!==f,w="+"===y||"*"===y,b="?"===y||"*"===y,x=e[2]||"/",k=l||d||(m?".*":"[^"+x+"]+?");n.push({name:h||r++,prefix:f||"",delimiter:x,optional:b,repeat:w,partial:g,asterisk:!!m,pattern:u(k)})}}return o<t.length&&(i+=t.substr(o)),i&&n.push(i),n}function n(t){return i(e(t))}function r(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function o(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function i(t){for(var e=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(e[n]=new RegExp("^(?:"+t[n].pattern+")$"));return function(n,i){for(var a="",u=n||{},c=i||{},s=c.pretty?r:encodeURIComponent,p=0;p<t.length;p++){var f=t[p];if("string"!=typeof f){var h,l=u[f.name];if(null==l){if(f.optional){f.partial&&(a+=f.prefix);continue}throw new TypeError('Expected "'+f.name+'" to be defined')}if(y(l)){if(!f.repeat)throw new TypeError('Expected "'+f.name+'" to not repeat, but received `'+JSON.stringify(l)+"`");if(0===l.length){if(f.optional)continue;throw new TypeError('Expected "'+f.name+'" to not be empty')}for(var d=0;d<l.length;d++){if(h=s(l[d]),!e[p].test(h))throw new TypeError('Expected all "'+f.name+'" to match "'+f.pattern+'", but received `'+JSON.stringify(h)+"`");a+=(0===d?f.prefix:f.delimiter)+h}}else{if(h=f.asterisk?o(l):s(l),!e[p].test(h))throw new TypeError('Expected "'+f.name+'" to match "'+f.pattern+'", but received "'+h+'"');a+=f.prefix+h}}else a+=f}return a}}function a(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function u(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function c(t,e){return t.keys=e,t}function s(t){return t.sensitive?"":"i"}function p(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return c(t,e)}function f(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(d(t[o],e,n).source);var i=new RegExp("(?:"+r.join("|")+")",s(n));return c(i,e)}function h(t,n,r){for(var o=e(t),i=l(o,r),a=0;a<o.length;a++)"string"!=typeof o[a]&&n.push(o[a]);return c(i,n)}function l(t,e){e=e||{};for(var n=e.strict,r=e.end!==!1,o="",i=t[t.length-1],u="string"==typeof i&&/\/$/.test(i),c=0;c<t.length;c++){var p=t[c];if("string"==typeof p)o+=a(p);else{var f=a(p.prefix),h="(?:"+p.pattern+")";p.repeat&&(h+="(?:"+f+h+")*"),h=p.optional?p.partial?f+"("+h+")?":"(?:"+f+"("+h+"))?":f+"("+h+")",o+=h}}return n||(o=(u?o.slice(0,-2):o)+"(?:\\/(?=$))?"),o+=r?"$":n&&u?"":"(?=\\/|$)",new RegExp("^"+o,s(e))}function d(t,e,n){return e=e||[],y(e)?n||(n={}):(n=e,e=[]),t instanceof RegExp?p(t,e):y(t)?f(t,e,n):h(t,e,n)}var y=g(et);t.exports=d,t.exports.parse=e,t.exports.compile=n,t.exports.tokensToFunction=i,t.exports.tokensToRegExp=l;var v=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g")}),rt=g(nt),ot=Object.create(null),it=Object.create(null),at="undefined"!=typeof window,ut=at&&function(){var t=window.navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history)}(),ct=function(t,e){this.router=t,this.base=$(e),this.current=c(null,{path:"__vue_router_init__"}),this.pending=null};ct.prototype.listen=function(t){this.cb=t},ct.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r)})},ct.prototype.confirmTransition=function(t,e){var n=this;if(!f(t,this.current)){var r=A(this.current.matched,t.matched),o=r.deactivated,i=r.activated,a=[].concat(R(o),this.router.beforeHooks,i.map(function(t){return t.beforeEnter}),q(i));this.pending=t;var u=function(t){return n.push(t)},c=function(e,n){return e(t,u,n)};S(a,c,function(){var r=[];S(T(i,r),c,function(){f(t,n.pending)&&(n.pending=null,e(t),n.router.app.$nextTick(function(){r.forEach(function(t){return t()})}))})})}},ct.prototype.updateRoute=function(t){this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(e){e&&e(t)})};var st=function(){return String(Date.now())},pt=st(),ft=function(t){function e(e,r){var o=this;t.call(this,e,r);var i=U(this.base);this.transitionTo(i,function(t){var e=n(o.base+o.current.fullPath);i!==e&&F(e)});var a=e.options.scrollBehavior;window.addEventListener("popstate",function(t){pt=t.state&&t.state.key;var e=o.current;o.transitionTo(U(o.base),function(t){a&&o.handleScroll(t,e,!0)})}),a&&window.addEventListener("scroll",function(){P(pt)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(e){var r=this,o=this.current;t.prototype.transitionTo.call(this,e,function(t){z(n(r.base+t.fullPath)),r.handleScroll(t,o,!1)})},e.prototype.replace=function(e){var r=this,o=this.current;t.prototype.transitionTo.call(this,e,function(t){F(n(r.base+t.fullPath)),r.handleScroll(t,o,!1)})},e.prototype.handleScroll=function(t,e,n){var o=this.router;if(o.app){var i=o.options.scrollBehavior;i&&(r("function"==typeof i,"scrollBehavior must be a function"),o.app.$nextTick(function(){var r=V(pt),o=i(t,e,n?r:null);if(o){var a="object"==typeof o;if(a&&o.selector){var u=document.querySelector(o.selector);u?r=B(u):H(o)&&(r=I(o))}else a&&H(o)&&(r=I(o));r&&window.scrollTo(r.x,r.y)}}))}},e}(ct),ht=function(t){function e(e,n,r){var o=this;t.call(this,e,n),r&&this.checkFallback()||(J(),this.transitionTo(N(),function(t){N()!==t.fullPath&&D(t.fullPath)}),window.addEventListener("hashchange",function(){o.onHashChange()}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkFallback=function(){var t=U(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.onHashChange=function(){J()&&this.transitionTo(N(),function(t){D(t.fullPath)})},e.prototype.push=function(e){t.prototype.transitionTo.call(this,e,function(t){L(t.fullPath)})},e.prototype.replace=function(e){t.prototype.transitionTo.call(this,e,function(t){D(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e}(ct),lt=function(t){function e(e){t.call(this,e),this.stack=[],this.index=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++})},e.prototype.replace=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e}(ct),dt=function(t){void 0===t&&(t={}),this.app=null,this.options=t,this.beforeHooks=[],this.afterHooks=[],this.match=O(t.routes||[]);var e=t.mode||"hash";this.fallback="history"===e&&!ut,this.fallback&&(e="hash"),at||(e="abstract"),this.mode=e},yt={currentRoute:{}};return yt.currentRoute.get=function(){return this.history&&this.history.current},dt.prototype.init=function(t){var e=this;r(m.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before creating root instance."),this.app=t;var n=this,o=n.mode,i=n.options,a=n.fallback;switch(o){case"history":this.history=new ft(this,i.base);break;case"hash":this.history=new ht(this,i.base,a);break;case"abstract":this.history=new lt(this);break;default:r(!1,"invalid mode: "+o)}this.history.listen(function(t){e.app._route=t})},dt.prototype.beforeEach=function(t){this.beforeHooks.push(t)},dt.prototype.afterEach=function(t){this.afterHooks.push(t)},dt.prototype.push=function(t){this.history.push(t)},dt.prototype.replace=function(t){this.history.replace(t)},dt.prototype.go=function(t){this.history.go(t)},dt.prototype.back=function(){this.go(-1)},dt.prototype.forward=function(){this.go(1)},dt.prototype.getMatchedComponents=function(){return this.currentRoute?[].concat.apply([],this.currentRoute.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Object.defineProperties(dt.prototype,yt),dt.install=m,at&&window.Vue&&window.Vue.use(dt),dt}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueRouter=e()}(this,function(){"use strict";function t(t,e,n){if("/"===t.charAt(0))return t;if("?"===t.charAt(0)||"#"===t.charAt(0))return e+t;var r=e.split("/");n&&r[r.length-1]||r.pop();for(var o=t.replace(/^\//,"").split("/"),i=0;i<o.length;i++){var a=o[i];"."!==a&&(".."===a?r.pop():r.push(a))}return""!==r[0]&&r.unshift(""),r.join("/")}function e(t){var e="",n="",r=t.indexOf("#");r>=0&&(e=t.slice(r),t=t.slice(0,r));var o=t.indexOf("?");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{path:t,query:n,hash:e}}function n(t){return t.replace(/\/\//g,"/")}function r(t,e){if(!t)throw new Error("[vue-router] "+e)}function o(t,e){t||"undefined"!=typeof console&&console.warn("[vue-router] "+e)}function i(t,e){if(void 0===e&&(e={}),t){var n;try{n=a(t)}catch(t){o(!1,t.message),n={}}for(var r in e)n[r]=e[r];return n}return e}function a(t){var e=Object.create(null);return(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var n=t.replace(/\+/g," ").split("="),r=ut(n.shift()),o=n.length>0?ut(n.join("=")):null;void 0===e[r]?e[r]=o:Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]}),e):e}function u(t){var e=t?Object.keys(t).sort().map(function(e){var n=t[e];if(void 0===n)return"";if(null===n)return at(e);if(Array.isArray(n)){var r=[];return n.slice().forEach(function(t){void 0!==t&&(null===t?r.push(at(e)):r.push(at(e)+"="+at(t)))}),r.join("&")}return at(e)+"="+at(n)}).filter(function(t){return t.length>0}).join("&"):null;return e?"?"+e:""}function c(t,e,n){var r={name:e.name||t&&t.name,meta:t&&t.meta||{},path:e.path||"/",hash:e.hash||"",query:e.query||{},params:e.params||{},fullPath:p(e),matched:t?s(t):[]};return n&&(r.redirectedFrom=p(n)),Object.freeze(r)}function s(t){for(var e=[];t;)e.unshift(t),t=t.parent;return e}function p(t){var e=t.path,n=t.query;void 0===n&&(n={});var r=t.hash;return void 0===r&&(r=""),(e||"/")+u(n)+r}function f(t,e){return e===ct?t===e:!!e&&(t.path&&e.path?t.path.replace(st,"")===e.path.replace(st,"")&&t.hash===e.hash&&h(t.query,e.query):!(!t.name||!e.name)&&(t.name===e.name&&t.hash===e.hash&&h(t.query,e.query)&&h(t.params,e.params)))}function h(t,e){void 0===t&&(t={}),void 0===e&&(e={});var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every(function(n){return String(t[n])===String(e[n])})}function l(t,e){return 0===t.path.indexOf(e.path)&&(!e.hash||t.hash===e.hash)&&d(t.query,e.query)}function d(t,e){for(var n in e)if(!(n in t))return!1;return!0}function y(n,r,o){var a="string"==typeof n?{path:n}:n;if(a.name||a._normalized)return a;var u=e(a.path||""),c=r&&r.path||"/",s=u.path?t(u.path,c,o):r&&r.path||"/",p=i(u.query,a.query),f=a.hash||u.hash;return f&&"#"!==f.charAt(0)&&(f="#"+f),{_normalized:!0,path:s,query:p,hash:f}}function v(t){if(t)for(var e,n=0;n<t.length;n++){if(e=t[n],"a"===e.tag)return e;if(e.children&&(e=v(e.children)))return e}}function m(t){m.installed||(m.installed=!0,Object.defineProperty(t.prototype,"$router",{get:function(){return this.$root._router}}),Object.defineProperty(t.prototype,"$route",{get:function(){return this.$root._route}}),t.mixin({beforeCreate:function(){this.$options.router&&(this._router=this.$options.router,this._router.init(this),t.util.defineReactive(this,"_route",this._router.history.current))}}),t.component("router-view",it),t.component("router-link",ft))}function g(t){for(var e,n=[],r=0,o=0,i="";null!=(e=wt.exec(t));){var a=e[0],u=e[1],c=e.index;if(i+=t.slice(o,c),o=c+a.length,u)i+=u[1];else{var s=t[o],p=e[2],f=e[3],h=e[4],l=e[5],d=e[6],y=e[7];i&&(n.push(i),i="");var v=null!=p&&null!=s&&s!==p,m="+"===d||"*"===d,g="?"===d||"*"===d,w=e[2]||"/",b=h||l||(y?".*":"[^"+w+"]+?");n.push({name:f||r++,prefix:p||"",delimiter:w,optional:g,repeat:m,partial:v,asterisk:!!y,pattern:E(b)})}}return o<t.length&&(i+=t.substr(o)),i&&n.push(i),n}function w(t){return k(g(t))}function b(t){return encodeURI(t).replace(/[\/?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function x(t){return encodeURI(t).replace(/[?#]/g,function(t){return"%"+t.charCodeAt(0).toString(16).toUpperCase()})}function k(t){for(var e=new Array(t.length),n=0;n<t.length;n++)"object"==typeof t[n]&&(e[n]=new RegExp("^(?:"+t[n].pattern+")$"));return function(n,r){for(var o="",i=n||{},a=r||{},u=a.pretty?b:encodeURIComponent,c=0;c<t.length;c++){var s=t[c];if("string"!=typeof s){var p,f=i[s.name];if(null==f){if(s.optional){s.partial&&(o+=s.prefix);continue}throw new TypeError('Expected "'+s.name+'" to be defined')}if(lt(f)){if(!s.repeat)throw new TypeError('Expected "'+s.name+'" to not repeat, but received `'+JSON.stringify(f)+"`");if(0===f.length){if(s.optional)continue;throw new TypeError('Expected "'+s.name+'" to not be empty')}for(var h=0;h<f.length;h++){if(p=u(f[h]),!e[c].test(p))throw new TypeError('Expected all "'+s.name+'" to match "'+s.pattern+'", but received `'+JSON.stringify(p)+"`");o+=(0===h?s.prefix:s.delimiter)+p}}else{if(p=s.asterisk?x(f):u(f),!e[c].test(p))throw new TypeError('Expected "'+s.name+'" to match "'+s.pattern+'", but received "'+p+'"');o+=s.prefix+p}}else o+=s}return o}}function O(t){return t.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function E(t){return t.replace(/([=!:$\/()])/g,"\\$1")}function j(t,e){return t.keys=e,t}function R(t){return t.sensitive?"":"i"}function S(t,e){var n=t.source.match(/\((?!\?)/g);if(n)for(var r=0;r<n.length;r++)e.push({name:r,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return j(t,e)}function $(t,e,n){for(var r=[],o=0;o<t.length;o++)r.push(T(t[o],e,n).source);var i=new RegExp("(?:"+r.join("|")+")",R(n));return j(i,e)}function A(t,e,n){for(var r=g(t),o=_(r,n),i=0;i<r.length;i++)"string"!=typeof r[i]&&e.push(r[i]);return j(o,e)}function _(t,e){e=e||{};for(var n=e.strict,r=e.end!==!1,o="",i=t[t.length-1],a="string"==typeof i&&/\/$/.test(i),u=0;u<t.length;u++){var c=t[u];if("string"==typeof c)o+=O(c);else{var s=O(c.prefix),p="(?:"+c.pattern+")";c.repeat&&(p+="(?:"+s+p+")*"),p=c.optional?c.partial?s+"("+p+")?":"(?:"+s+"("+p+"))?":s+"("+p+")",o+=p}}return n||(o=(a?o.slice(0,-2):o)+"(?:\\/(?=$))?"),o+=r?"$":n&&a?"":"(?=\\/|$)",new RegExp("^"+o,R(e))}function T(t,e,n){return e=e||[],lt(e)?n||(n={}):(n=e,e=[]),t instanceof RegExp?S(t,e):lt(t)?$(t,e,n):A(t,e,n)}function q(t){var e=Object.create(null),n=Object.create(null);return t.forEach(function(t){C(e,n,t)}),{pathMap:e,nameMap:n}}function C(t,e,n,o,i){var a=n.path,u=n.name;r(null!=a,'"path" is required in a route configuration.');var c={path:P(a,o),components:n.components||{default:n.component},instances:{},name:u,parent:o,matchAs:i,redirect:n.redirect,beforeEnter:n.beforeEnter,meta:n.meta||{}};n.children&&n.children.forEach(function(n){C(t,e,n,c)}),n.alias&&(Array.isArray(n.alias)?n.alias.forEach(function(n){C(t,e,{path:n},o,c.path)}):C(t,e,{path:n.alias},o,c.path)),t[c.path]=c,u&&(e[u]=c)}function P(t,e){return t=t.replace(/\/$/,""),"/"===t[0]?t:null==e?t:n(e.path+"/"+t)}function U(t){function e(t,e,n){var r=y(t,e),o=r.name;if(o){var i=p[o];if(i)return r.path=L(i.path,r.params,'named route "'+o+'"'),a(i,r,n)}else if(r.path){r.params={};for(var u in s)if(V(u,r.params,r.path))return a(s[u],r,n)}return a(null,r)}function n(t,n){var i=t.redirect,u="function"==typeof i?i(c(t,n)):i;if("string"==typeof u&&(u={path:u}),!u||"object"!=typeof u)return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n);var s=u,f=s.name,h=s.path,l=n.query,d=n.hash,y=n.params;if(l=s.hasOwnProperty("query")?s.query:l,d=s.hasOwnProperty("hash")?s.hash:d,y=s.hasOwnProperty("params")?s.params:y,f){var v=p[f];return r(v,'redirect failed: named route "'+f+'" not found.'),e({_normalized:!0,name:f,query:l,hash:d,params:y},void 0,n)}if(h){var m=B(h,t),g=L(m,y,'redirect route with path "'+m+'"');return e({_normalized:!0,path:g,query:l,hash:d},void 0,n)}return o(!1,"invalid redirect option: "+JSON.stringify(u)),a(null,n)}function i(t,n,r){var o=L(r,n.params,'aliased route with path "'+r+'"'),i=e({_normalized:!0,path:o});if(i){var u=i.matched,c=u[u.length-1];return n.params=i.params,a(c,n)}return a(null,n)}function a(t,e,r){return t&&t.redirect?n(t,r||e):t&&t.matchAs?i(t,e,t.matchAs):c(t,e,r)}var u=q(t),s=u.pathMap,p=u.nameMap;return e}function V(t,e,n){var r,o,i=bt[t];i?(r=i.keys,o=i.regexp):(r=[],o=dt(t,r),bt[t]={keys:r,regexp:o});var a=n.match(o);if(!a)return!1;if(!e)return!0;for(var u=1,c=a.length;u<c;++u){var s=r[u-1],p="string"==typeof a[u]?decodeURIComponent(a[u]):a[u];s&&(e[s.name]=p)}return!0}function L(t,e,n){try{var o=xt[t]||(xt[t]=dt.compile(t));return o(e||{},{pretty:!0})}catch(t){return r(!1,"missing param for "+n+": "+t.message),""}}function B(e,n){return t(e,n.parent?n.parent.path:"/",!0)}function H(t,e,n){var r=function(o){o>=t.length?n():t[o]?e(t[o],function(){r(o+1)}):r(o+1)};r(0)}function I(t){if(!t)if(kt){var e=document.querySelector("base");t=e?e.getAttribute("href"):"/"}else t="/";return"/"!==t.charAt(0)&&(t="/"+t),t.replace(/\/$/,"")}function M(t,e){var n,r=Math.max(t.length,e.length);for(n=0;n<r&&t[n]===e[n];n++);return{activated:e.slice(n),deactivated:t.slice(n)}}function z(t){return N(t,function(t,e){var n=t&&t.beforeRouteLeave;if(n)return function(){return n.apply(e,arguments)}}).reverse()}function F(t,e){return N(t,function(t,n,r,o){var i=t&&t.beforeRouteEnter;if(i)return function(t,n,a){return i(t,n,function(t){a(t),"function"==typeof t&&e.push(function(){t(r.instances[o])})})}})}function J(t){return N(t,function(t,e,n,r){if("function"==typeof t&&!t.options)return function(e,i,a){var u=function(t){n.components[r]=t,a()},c=function(t){o(!1,"Failed to resolve async component "+r+": "+t),a(!1)},s=t(u,c);s&&"function"==typeof s.then&&s.then(u,c)}})}function N(t,e){return Array.prototype.concat.apply([],t.map(function(t){return Object.keys(t.components).map(function(n){return e(t.components[n],t.instances[n],t,n)})}))}function D(t){t&&window.sessionStorage.setItem(t,JSON.stringify({x:window.pageXOffset,y:window.pageYOffset}))}function X(t){if(t)return JSON.parse(window.sessionStorage.getItem(t))}function Y(t){var e=document.documentElement.getBoundingClientRect(),n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top}}function W(t){return K(t.x)||K(t.y)}function G(t){return{x:K(t.x)?t.x:window.pageXOffset,y:K(t.y)?t.y:window.pageYOffset}}function K(t){return"number"==typeof t}function Q(t){var e=window.location.pathname;return t&&0===e.indexOf(t)&&(e=e.slice(t.length)),(e||"/")+window.location.search+window.location.hash}function Z(t,e){var n=window.history;try{e?n.replaceState({key:Rt},"",t):(Rt=jt(),n.pushState({key:Rt},"",t)),D(Rt)}catch(n){window.location[e?"assign":"replace"](t)}}function tt(t){Z(t,!0)}function et(){var t=nt();return"/"===t.charAt(0)||(ot("/"+t),!1)}function nt(){var t=window.location.href,e=t.indexOf("#");return e===-1?"":t.slice(e+1)}function rt(t){window.location.hash=t}function ot(t){var e=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,e>=0?e:0)+"#"+t)}var it={name:"router-view",functional:!0,props:{name:{type:String,default:"default"}},render:function(t,e){var n=e.props,r=e.children,o=e.parent,i=e.data;i.routerView=!0;for(var a=o.$route,u=o._routerViewCache||(o._routerViewCache={}),c=0,s=!1;o;)o.$vnode&&o.$vnode.data.routerView&&c++,o._inactive&&(s=!0),o=o.$parent;i.routerViewDepth=c;var p=a.matched[c];if(!p)return t();var f=s?u[n.name]:u[n.name]=p.components[n.name];return s||((i.hook||(i.hook={})).init=function(t){p.instances[n.name]=t.child}),t(f,i,r)}},at=encodeURIComponent,ut=decodeURIComponent,ct=c(null,{path:"/"}),st=/\/$/,pt=[String,Object],ft={name:"router-link",props:{to:{type:pt,required:!0},tag:{type:String,default:"a"},exact:Boolean,append:Boolean,replace:Boolean,activeClass:String},render:function(t){var e=this,r=this.$router,o=this.$route,i=y(this.to,o,this.append),a=r.match(i),u=a.redirectedFrom||a.fullPath,s=r.history.base,p=s?n(s+u):u,h={},d=this.activeClass||r.options.linkActiveClass||"router-link-active",m=i.path?c(null,i):a;h[d]=this.exact?f(o,m):l(o,m);var g={click:function(t){t.preventDefault(),e.replace?r.replace(i):r.push(i)}},w={class:h};if("a"===this.tag)w.on=g,w.attrs={href:p};else{var b=v(this.$slots.default);if(b){var x=b.data||(b.data={});x.on=g;var k=x.attrs||(x.attrs={});k.href=p}}return t(this.tag,w,this.$slots.default)}},ht=Array.isArray||function(t){return"[object Array]"==Object.prototype.toString.call(t)},lt=ht,dt=T,yt=g,vt=w,mt=k,gt=_,wt=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");dt.parse=yt,dt.compile=vt,dt.tokensToFunction=mt,dt.tokensToRegExp=gt;var bt=Object.create(null),xt=Object.create(null),kt="undefined"!=typeof window,Ot=kt&&function(){var t=window.navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history)}(),Et=function(t,e){this.router=t,this.base=I(e),this.current=ct,this.pending=null};Et.prototype.listen=function(t){this.cb=t},Et.prototype.transitionTo=function(t,e){var n=this,r=this.router.match(t,this.current);this.confirmTransition(r,function(){n.updateRoute(r),e&&e(r),n.ensureURL()})},Et.prototype.confirmTransition=function(t,e){var n=this,r=this.current;if(f(t,r))return void this.ensureURL();var o=M(this.current.matched,t.matched),i=o.deactivated,a=o.activated,u=[].concat(z(i),this.router.beforeHooks,a.map(function(t){return t.beforeEnter}),J(a));this.pending=t;var c=function(e,o){n.pending===t&&e(t,r,function(t){t===!1?n.ensureURL():"string"==typeof t||"object"==typeof t?n.push(t):o(t)})};H(u,c,function(){var r=[];H(F(a,r),c,function(){n.pending===t&&(n.pending=null,e(t),n.router.app.$nextTick(function(){r.forEach(function(t){return t()})}))})})},Et.prototype.updateRoute=function(t){var e=this.current;this.current=t,this.cb&&this.cb(t),this.router.afterHooks.forEach(function(n){n&&n(t,e)})};var jt=function(){return String(Date.now())},Rt=jt(),St=function(t){function e(e,n){var r=this;t.call(this,e,n),this.transitionTo(Q(this.base));var o=e.options.scrollBehavior;window.addEventListener("popstate",function(t){Rt=t.state&&t.state.key;var e=r.current;r.transitionTo(Q(r.base),function(t){o&&r.handleScroll(t,e,!0)})}),o&&window.addEventListener("scroll",function(){D(Rt)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.go=function(t){window.history.go(t)},e.prototype.push=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){Z(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.replace=function(t){var e=this,r=this.current;this.transitionTo(t,function(t){tt(n(e.base+t.fullPath)),e.handleScroll(t,r,!1)})},e.prototype.ensureURL=function(){Q(this.base)!==this.current.fullPath&&tt(n(this.base+this.current.fullPath))},e.prototype.handleScroll=function(t,e,n){var o=this.router;if(o.app){var i=o.options.scrollBehavior;i&&(r("function"==typeof i,"scrollBehavior must be a function"),o.app.$nextTick(function(){var r=X(Rt),o=i(t,e,n?r:null);if(o){var a="object"==typeof o;if(a&&"string"==typeof o.selector){var u=document.querySelector(o.selector);u?r=Y(u):W(o)&&(r=G(o))}else a&&W(o)&&(r=G(o));r&&window.scrollTo(r.x,r.y)}}))}},e}(Et),$t=function(t){function e(e,n,r){var o=this;t.call(this,e,n),r&&this.checkFallback()||(et(),this.transitionTo(nt()),window.addEventListener("hashchange",function(){o.onHashChange()}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.checkFallback=function(){var t=Q(this.base);if(!/^\/#/.test(t))return window.location.replace(n(this.base+"/#"+t)),!0},e.prototype.ensureURL=function(){nt()!==this.current.fullPath&&ot(this.current.fullPath)},e.prototype.onHashChange=function(){et()&&this.transitionTo(nt(),function(t){ot(t.fullPath)})},e.prototype.push=function(e){t.prototype.transitionTo.call(this,e,function(t){rt(t.fullPath)})},e.prototype.replace=function(e){t.prototype.transitionTo.call(this,e,function(t){ot(t.fullPath)})},e.prototype.go=function(t){window.history.go(t)},e}(Et),At=function(t){function e(e){t.call(this,e),this.stack=[],this.index=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.push=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index+1).concat(t),n.index++})},e.prototype.replace=function(e){var n=this;t.prototype.transitionTo.call(this,e,function(t){n.stack=n.stack.slice(0,n.index).concat(t)})},e.prototype.go=function(t){var e=this,n=this.index+t;if(!(n<0||n>=this.stack.length)){var r=this.stack[n];this.confirmTransition(r,function(){e.index=n,e.updateRoute(r)})}},e}(Et),_t=function(t){void 0===t&&(t={}),this.app=null,this.options=t,this.beforeHooks=[],this.afterHooks=[],this.match=U(t.routes||[]);var e=t.mode||"hash";this.fallback="history"===e&&!Ot,this.fallback&&(e="hash"),kt||(e="abstract"),this.mode=e},Tt={currentRoute:{}};return Tt.currentRoute.get=function(){return this.history&&this.history.current},_t.prototype.init=function(t){var e=this;r(m.installed,"not installed. Make sure to call `Vue.use(VueRouter)` before creating root instance."),this.app=t;var n=this,o=n.mode,i=n.options,a=n.fallback;switch(o){case"history":this.history=new St(this,i.base);break;case"hash":this.history=new $t(this,i.base,a);break;case"abstract":this.history=new At(this);break;default:r(!1,"invalid mode: "+o)}this.history.listen(function(t){e.app._route=t})},_t.prototype.beforeEach=function(t){this.beforeHooks.push(t)},_t.prototype.afterEach=function(t){this.afterHooks.push(t)},_t.prototype.push=function(t){this.history.push(t)},_t.prototype.replace=function(t){this.history.replace(t)},_t.prototype.go=function(t){this.history.go(t)},_t.prototype.back=function(){this.go(-1)},_t.prototype.forward=function(){this.go(1)},_t.prototype.getMatchedComponents=function(){return this.currentRoute?[].concat.apply([],this.currentRoute.matched.map(function(t){return Object.keys(t.components).map(function(e){return t.components[e]})})):[]},Object.defineProperties(_t.prototype,Tt),_t.install=m,kt&&window.Vue&&window.Vue.use(_t),_t}); |
{ | ||
"name": "vue-router", | ||
"version": "2.0.0-rc.5", | ||
"version": "2.0.0-rc.6", | ||
"description": "Official router for Vue.js 2.0", | ||
@@ -8,6 +8,10 @@ "author": "Evan You", | ||
"main": "dist/vue-router.js", | ||
"typings": "types/index.d.ts", | ||
"files": [ | ||
"dist/vue-router.js", | ||
"dist/vue-router.min.js", | ||
"src" | ||
"src", | ||
"types/index.d.ts", | ||
"types/router.d.ts", | ||
"types/vue.d.ts" | ||
], | ||
@@ -24,5 +28,8 @@ "keywords": [ | ||
"lint": "eslint src examples", | ||
"test": "npm run lint && flow check && npm run test:unit && npm run test:e2e", | ||
"test": "npm run lint && flow check && npm run test:unit && npm run test:e2e && npm run test:types", | ||
"test:unit": "jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json", | ||
"test:e2e": "node test/e2e/runner.js", | ||
"test:types": "tsc -p types/test", | ||
"docs": "cd docs && gitbook serve", | ||
"docs:deploy": "bash ./build/update-docs.sh", | ||
"release": "bash build/release.sh" | ||
@@ -35,8 +42,8 @@ }, | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-es2015-loose": "^7.0.0", | ||
"babel-preset-es2015-loose": "^8.0.0", | ||
"babel-preset-flow-vue": "^1.0.0", | ||
"buble": "^0.13.1", | ||
"buble": "^0.14.0", | ||
"chromedriver": "^2.21.2", | ||
"cross-spawn": "^4.0.0", | ||
"css-loader": "^0.24.0", | ||
"css-loader": "^0.25.0", | ||
"eslint": "^3.0.1", | ||
@@ -48,3 +55,5 @@ "eslint-config-vue": "^1.1.0", | ||
"express-urlrewrite": "^1.2.0", | ||
"flow-bin": "^0.31.1", | ||
"flow-bin": "^0.32.0", | ||
"gitbook-plugin-edit-link": "^2.0.2", | ||
"gitbook-plugin-github": "^2.0.0", | ||
"jasmine": "2.4.1", | ||
@@ -55,6 +64,6 @@ "nightwatch": "^0.9.5", | ||
"phantomjs-prebuilt": "^2.1.7", | ||
"rollup": "^0.34.10", | ||
"rollup-plugin-buble": "^0.13.0", | ||
"rollup-plugin-commonjs": "^3.1.0", | ||
"rollup-plugin-flow": "^1.0.0", | ||
"rollup": "^0.34.13", | ||
"rollup-plugin-buble": "^0.14.0", | ||
"rollup-plugin-commonjs": "^5.0.4", | ||
"rollup-plugin-flow-no-whitespace": "^1.0.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
@@ -64,4 +73,5 @@ "rollup-plugin-replace": "^1.1.1", | ||
"selenium-server": "^2.53.1", | ||
"typescript": "^2.0.3", | ||
"uglify-js": "^2.7.0", | ||
"vue": "^2.0.0-rc.6", | ||
"vue": "^2.0.0-rc.7", | ||
"vue-loader": "^9.4.0", | ||
@@ -68,0 +78,0 @@ "webpack": "^1.13.1", |
@@ -1,15 +0,65 @@ | ||
# vue-router-next [![CircleCI](https://img.shields.io/circleci/project/vuejs/vue-router/next.svg?maxAge=2592000)](https://circleci.com/gh/vuejs/vue-router/tree/next) | ||
# vue-router [![Build Status](https://img.shields.io/circleci/project/vuejs/vue-router/dev.svg)](https://circleci.com/gh/vuejs/vue-router) | ||
`vue-router` for Vue 2.0. | ||
> This is vue-router 2.0 which works only with Vue 2.0. For the 1.x router see the [1.0 branch](https://github.com/vuejs/vue-router/tree/1.0). | ||
This is still work in progress. There are numerous breaking changes from 0.7.x and docs are lacking - the best way to get started is checking out the examples. | ||
### Introduction | ||
`vue-router` is the official router for [Vue.js](http://vuejs.org). It deeply integrates with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include: | ||
- Nested route/view mapping | ||
- Modular, component-based router configuration | ||
- Route params, query, wildcards | ||
- View transition effects powered by Vue.js' transition system | ||
- Fine-grained navigation control | ||
- Links with automatic active CSS classes | ||
- HTML5 history mode or hash mode, with auto-fallback in IE9 | ||
- Customizable Scroll Behavior | ||
Get started with the [documentation](http://vuejs.github.io/vue-router), or play with the [examples](https://github.com/vuejs/vue-router/tree/dev/examples) (see how to run them below). | ||
### Development Setup | ||
``` bash | ||
# install deps | ||
npm install | ||
# build dist files | ||
npm run build | ||
# serve examples at localhost:8080 | ||
npm run dev | ||
# build dist files | ||
npm run build | ||
# lint & run all tests | ||
npm test | ||
# serve docs at localhost:4000 (requires global gitbook-cli) | ||
npm run docs | ||
``` | ||
## Questions | ||
For questions and support please use the [Gitter chat room](https://gitter.im/vuejs/vue) or [the official forum](http://forum.vuejs.org). The issue list of this repo is **exclusively** for bug reports and feature requests. | ||
## Issues | ||
Please make sure to read the [Issue Reporting Checklist](https://github.com/vuejs/vue/blob/dev/CONTRIBUTING.md#issue-reporting-guidelines) before opening an issue. Issues not conforming to the guidelines may be closed immediately. | ||
## Contribution | ||
Please make sure to read the [Contributing Guide](https://github.com/vuejs/vue/blob/dev/CONTRIBUTING.md) before making a pull request. | ||
## Changelog | ||
Details changes for each release are documented in the [release notes](https://github.com/vuejs/vue-router/releases). | ||
## Stay In Touch | ||
- For latest releases and announcements, follow on Twitter: [@vuejs](https://twitter.com/vuejs) | ||
## License | ||
[MIT](http://opensource.org/licenses/MIT) | ||
Copyright (c) 2013-2016 Evan You | ||
@@ -41,12 +41,9 @@ /* @flow */ | ||
const data: any = { | ||
class: classes, | ||
on: { | ||
click: (e) => { | ||
e.preventDefault() | ||
if (this.replace) { | ||
router.replace(to) | ||
} else { | ||
router.push(to) | ||
} | ||
const on = { | ||
click: (e) => { | ||
e.preventDefault() | ||
if (this.replace) { | ||
router.replace(to) | ||
} else { | ||
router.push(to) | ||
} | ||
@@ -56,9 +53,15 @@ } | ||
const data: any = { | ||
class: classes | ||
} | ||
if (this.tag === 'a') { | ||
data.on = on | ||
data.attrs = { href } | ||
} else { | ||
// find the first <a> child and apply href | ||
// find the first <a> child and apply listener and href | ||
const a = findAnchor(this.$slots.default) | ||
if (a) { | ||
const aData = a.data || (a.data = {}) | ||
aData.on = on | ||
const aAttrs = aData.attrs || (aData.attrs = {}) | ||
@@ -65,0 +68,0 @@ aAttrs.href = href |
@@ -7,7 +7,7 @@ /* @flow */ | ||
export function createRouteMap (routes: Array<RouteConfig>): { | ||
pathMap: RouteMap, | ||
nameMap: RouteMap | ||
pathMap: Dictionary<RouteRecord>, | ||
nameMap: Dictionary<RouteRecord> | ||
} { | ||
const pathMap: RouteMap = Object.create(null) | ||
const nameMap: RouteMap = Object.create(null) | ||
const pathMap: Dictionary<RouteRecord> = Object.create(null) | ||
const nameMap: Dictionary<RouteRecord> = Object.create(null) | ||
@@ -25,4 +25,4 @@ routes.forEach(route => { | ||
function addRouteRecord ( | ||
pathMap: RouteMap, | ||
nameMap: RouteMap, | ||
pathMap: Dictionary<RouteRecord>, | ||
nameMap: Dictionary<RouteRecord>, | ||
route: RouteConfig, | ||
@@ -29,0 +29,0 @@ parent?: RouteRecord, |
@@ -7,3 +7,3 @@ /* @flow */ | ||
import { runQueue } from '../util/async' | ||
import { createRoute, isSameRoute } from '../util/route' | ||
import { START, isSameRoute } from '../util/route' | ||
@@ -21,2 +21,3 @@ export class History { | ||
replace: (loc: RawLocation) => void; | ||
ensureURL: () => void; | ||
@@ -27,5 +28,3 @@ constructor (router: VueRouter, base: ?string) { | ||
// start with a route object that stands for "nowhere" | ||
this.current = createRoute(null, { | ||
path: '__vue_router_init__' | ||
}) | ||
this.current = START | ||
this.pending = null | ||
@@ -43,2 +42,3 @@ } | ||
cb && cb(route) | ||
this.ensureURL() | ||
}) | ||
@@ -48,3 +48,5 @@ } | ||
confirmTransition (route: Route, cb: Function) { | ||
if (isSameRoute(route, this.current)) { | ||
const current = this.current | ||
if (isSameRoute(route, current)) { | ||
this.ensureURL() | ||
return | ||
@@ -70,4 +72,17 @@ } | ||
this.pending = route | ||
const redirect = location => this.push(location) | ||
const iterator = (hook, next) => hook(route, redirect, next) | ||
const iterator = (hook, next) => { | ||
if (this.pending !== route) return | ||
hook(route, current, (to: any) => { | ||
if (to === false) { | ||
// next(false) -> abort navigation, ensure current URL | ||
this.ensureURL() | ||
} else if (typeof to === 'string' || typeof to === 'object') { | ||
// next('/') or next({ path: '/' }) -> redirect | ||
this.push(to) | ||
} else { | ||
// confirm transition and pass on the value | ||
next(to) | ||
} | ||
}) | ||
} | ||
@@ -79,3 +94,3 @@ runQueue(queue, iterator, () => { | ||
runQueue(extractEnterGuards(activated, postEnterCbs), iterator, () => { | ||
if (isSameRoute(route, this.pending)) { | ||
if (this.pending === route) { | ||
this.pending = null | ||
@@ -92,6 +107,7 @@ cb(route) | ||
updateRoute (route: Route) { | ||
const prev = this.current | ||
this.current = route | ||
this.cb && this.cb(route) | ||
this.router.afterHooks.forEach(hook => { | ||
hook && hook(route) | ||
hook && hook(route, prev) | ||
}) | ||
@@ -154,8 +170,10 @@ } | ||
if (guard) { | ||
return function routeEnterGuard (route, redirect, next) { | ||
return guard(route, redirect, cb => { | ||
next() | ||
cb && cbs.push(() => { | ||
cb(match.instances[key]) | ||
}) | ||
return function routeEnterGuard (to, from, next) { | ||
return guard(to, from, cb => { | ||
next(cb) | ||
if (typeof cb === 'function') { | ||
cbs.push(() => { | ||
cb(match.instances[key]) | ||
}) | ||
} | ||
}) | ||
@@ -175,3 +193,3 @@ } | ||
if (typeof def === 'function' && !def.options) { | ||
return (route, redirect, next) => { | ||
return (to, from, next) => { | ||
const resolve = resolvedDef => { | ||
@@ -184,2 +202,3 @@ match.components[key] = resolvedDef | ||
warn(false, `Failed to resolve async component ${key}: ${reason}`) | ||
next(false) | ||
} | ||
@@ -186,0 +205,0 @@ |
@@ -18,8 +18,3 @@ /* @flow */ | ||
ensureSlash() | ||
this.transitionTo(getHash(), route => { | ||
// possible redirect on start | ||
if (getHash() !== route.fullPath) { | ||
replaceHash(route.fullPath) | ||
} | ||
}) | ||
this.transitionTo(getHash()) | ||
@@ -41,2 +36,8 @@ window.addEventListener('hashchange', () => { | ||
ensureURL () { | ||
if (getHash() !== this.current.fullPath) { | ||
replaceHash(this.current.fullPath) | ||
} | ||
} | ||
onHashChange () { | ||
@@ -43,0 +44,0 @@ if (!ensureSlash()) { |
@@ -22,10 +22,3 @@ /* @flow */ | ||
const initialLocation = getLocation(this.base) | ||
this.transitionTo(initialLocation, route => { | ||
// possible redirect on start | ||
const url = cleanPath(this.base + this.current.fullPath) | ||
if (initialLocation !== url) { | ||
replaceState(url) | ||
} | ||
}) | ||
this.transitionTo(getLocation(this.base)) | ||
@@ -56,3 +49,3 @@ const expectScroll = router.options.scrollBehavior | ||
const current = this.current | ||
super.transitionTo(location, route => { | ||
this.transitionTo(location, route => { | ||
pushState(cleanPath(this.base + route.fullPath)) | ||
@@ -65,3 +58,3 @@ this.handleScroll(route, current, false) | ||
const current = this.current | ||
super.transitionTo(location, route => { | ||
this.transitionTo(location, route => { | ||
replaceState(cleanPath(this.base + route.fullPath)) | ||
@@ -72,2 +65,8 @@ this.handleScroll(route, current, false) | ||
ensureURL () { | ||
if (getLocation(this.base) !== this.current.fullPath) { | ||
replaceState(cleanPath(this.base + this.current.fullPath)) | ||
} | ||
} | ||
handleScroll (to: Route, from: Route, isPop: boolean) { | ||
@@ -93,3 +92,3 @@ const router = this.router | ||
const isObject = typeof shouldScroll === 'object' | ||
if (isObject && shouldScroll.selector) { | ||
if (isObject && typeof shouldScroll.selector === 'string') { | ||
const el = document.querySelector(shouldScroll.selector) | ||
@@ -96,0 +95,0 @@ if (el) { |
@@ -10,4 +10,4 @@ /* @flow */ | ||
query: ?string, | ||
extraQuery: StringHash = {} | ||
): StringHash { | ||
extraQuery: Dictionary<string> = {} | ||
): Dictionary<string> { | ||
if (query) { | ||
@@ -30,3 +30,3 @@ let parsedQuery | ||
function parseQuery (query: string): StringHash { | ||
function parseQuery (query: string): Dictionary<string> { | ||
const res = Object.create(null) | ||
@@ -59,3 +59,3 @@ | ||
export function stringifyQuery (obj: StringHash): string { | ||
export function stringifyQuery (obj: Dictionary<string>): string { | ||
const res = obj ? Object.keys(obj).sort().map(key => { | ||
@@ -62,0 +62,0 @@ const val = obj[key] |
@@ -26,2 +26,7 @@ /* @flow */ | ||
// the starting route that represents the initial state | ||
export const START = createRoute(null, { | ||
path: '/' | ||
}) | ||
function formatMatch (record: ?RouteRecord): Array<RouteRecord> { | ||
@@ -42,3 +47,5 @@ const res = [] | ||
export function isSameRoute (a: Route, b: ?Route): boolean { | ||
if (!b) { | ||
if (b === START) { | ||
return a === b | ||
} else if (!b) { | ||
return false | ||
@@ -80,3 +87,3 @@ } else if (a.path && b.path) { | ||
function queryIncludes (current: StringHash, target: StringHash): boolean { | ||
function queryIncludes (current: Dictionary<string>, target: Dictionary<string>): boolean { | ||
for (const key in target) { | ||
@@ -83,0 +90,0 @@ if (!(key in current)) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105075
25
2920
66
38