Skip to content

Commit

Permalink
[build] 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 17, 2017
1 parent 952fb68 commit a329938
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 131 deletions.
122 changes: 79 additions & 43 deletions dist/vue-router.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vue-router v2.5.3
* vue-router v2.6.0
* (c) 2017 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ var View = {
// has been toggled inactive but kept-alive.
var depth = 0;
var inactive = false;
while (parent) {
while (parent && parent._routerRoot !== parent) {
if (parent.$vnode && parent.$vnode.data.routerView) {
depth++;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ function stringifyQuery (obj) {

if (Array.isArray(val)) {
var result = [];
val.slice().forEach(function (val2) {
val.forEach(function (val2) {
if (val2 === undefined) {
return
}
Expand Down Expand Up @@ -302,7 +302,15 @@ function isObjectEqual (a, b) {
if (aKeys.length !== bKeys.length) {
return false
}
return aKeys.every(function (key) { return String(a[key]) === String(b[key]); })
return aKeys.every(function (key) {
var aVal = a[key];
var bVal = b[key];
// check nested equality
if (typeof aVal === 'object' && typeof bVal === 'object') {
return isObjectEqual(aVal, bVal)
}
return String(aVal) === String(bVal)
})
}

function isIncludedRoute (current, target) {
Expand Down Expand Up @@ -433,7 +441,7 @@ var Link = {

function guardEvent (e) {
// don't redirect with control keys
if (e.metaKey || e.ctrlKey || e.shiftKey) { return }
if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) { return }
// don't redirect when preventDefault called
if (e.defaultPrevented) { return }
// don't redirect on right click
Expand Down Expand Up @@ -473,14 +481,6 @@ function install (Vue) {

_Vue = Vue;

Object.defineProperty(Vue.prototype, '$router', {
get: function get () { return this.$root._router }
});

Object.defineProperty(Vue.prototype, '$route', {
get: function get () { return this.$root._route }
});

var isDef = function (v) { return v !== undefined; };

var registerInstance = function (vm, callVal) {
Expand All @@ -493,9 +493,12 @@ function install (Vue) {
Vue.mixin({
beforeCreate: function beforeCreate () {
if (isDef(this.$options.router)) {
this._routerRoot = this;
this._router = this.$options.router;
this._router.init(this);
Vue.util.defineReactive(this, '_route', this._router.history.current);
} else {
this._routerRoot = (this.$parent && this.$parent._routerRoot) || this;
}
registerInstance(this, this);
},
Expand All @@ -504,6 +507,14 @@ function install (Vue) {
}
});

Object.defineProperty(Vue.prototype, '$router', {
get: function get () { return this._routerRoot._router }
});

Object.defineProperty(Vue.prototype, '$route', {
get: function get () { return this._routerRoot._route }
});

Vue.component('router-view', View);
Vue.component('router-link', Link);

Expand Down Expand Up @@ -1096,9 +1107,15 @@ function addRouteRecord (
}

var normalizedPath = normalizePath(path, parent);
var pathToRegexpOptions = route.pathToRegexpOptions || {};

if (typeof route.caseSensitive === 'boolean') {
pathToRegexpOptions.sensitive = route.caseSensitive;
}

var record = {
path: normalizedPath,
regex: compileRouteRegex(normalizedPath),
regex: compileRouteRegex(normalizedPath, pathToRegexpOptions),
components: route.components || { default: route.component },
instances: {},
name: name,
Expand All @@ -1115,11 +1132,11 @@ function addRouteRecord (
};

if (route.children) {
// Warn if route is named and has a default child route.
// Warn if route is named, does not redirect and has a default child route.
// If users navigate to this route by name, the default child will
// not be rendered (GH Issue #629)
if (process.env.NODE_ENV !== 'production') {
if (route.name && route.children.some(function (child) { return /^\/?$/.test(child.path); })) {
if (route.name && !route.redirect && route.children.some(function (child) { return /^\/?$/.test(child.path); })) {
warn(
false,
"Named Route '" + (route.name) + "' has a default child route. " +
Expand All @@ -1139,21 +1156,24 @@ function addRouteRecord (
}

if (route.alias !== undefined) {
if (Array.isArray(route.alias)) {
route.alias.forEach(function (alias) {
var aliasRoute = {
path: alias,
children: route.children
};
addRouteRecord(pathList, pathMap, nameMap, aliasRoute, parent, record.path);
});
} else {
var aliases = Array.isArray(route.alias)
? route.alias
: [route.alias];

aliases.forEach(function (alias) {
var aliasRoute = {
path: route.alias,
path: alias,
children: route.children
};
addRouteRecord(pathList, pathMap, nameMap, aliasRoute, parent, record.path);
}
addRouteRecord(
pathList,
pathMap,
nameMap,
aliasRoute,
parent,
record.path || '/' // matchAs
);
});
}

if (!pathMap[record.path]) {
Expand All @@ -1174,8 +1194,8 @@ function addRouteRecord (
}
}

function compileRouteRegex (path) {
var regex = index(path);
function compileRouteRegex (path, pathToRegexpOptions) {
var regex = index(path, [], pathToRegexpOptions);
if (process.env.NODE_ENV !== 'production') {
var keys = {};
regex.keys.forEach(function (key) {
Expand Down Expand Up @@ -1216,7 +1236,7 @@ function normalizeLocation (
if (current.name) {
next.name = current.name;
next.params = params;
} else if (current.matched) {
} else if (current.matched.length) {
var rawPath = current.matched[current.matched.length - 1].path;
next.path = fillParams(rawPath, params, ("path " + (current.path)));
} else if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -1286,6 +1306,7 @@ function createMatcher (
if (process.env.NODE_ENV !== 'production') {
warn(record, ("Route with name '" + name + "' does not exist"));
}
if (!record) { return _createRoute(null, location) }
var paramNames = record.regex.keys
.filter(function (key) { return !key.optional; })
.map(function (key) { return key.name; });
Expand Down Expand Up @@ -1496,7 +1517,9 @@ function handleScroll (
if (isObject && typeof shouldScroll.selector === 'string') {
var el = document.querySelector(shouldScroll.selector);
if (el) {
position = getElementPosition(el);
var offset = shouldScroll.offset && typeof shouldScroll.offset === 'object' ? shouldScroll.offset : {};
offset = normalizeOffset(offset);
position = getElementPosition(el, offset);
} else if (isValidPosition(shouldScroll)) {
position = normalizePosition(shouldScroll);
}
Expand Down Expand Up @@ -1527,13 +1550,13 @@ function getScrollPosition () {
}
}

function getElementPosition (el) {
function getElementPosition (el, offset) {
var docEl = document.documentElement;
var docRect = docEl.getBoundingClientRect();
var elRect = el.getBoundingClientRect();
return {
x: elRect.left - docRect.left,
y: elRect.top - docRect.top
x: elRect.left - docRect.left - offset.x,
y: elRect.top - docRect.top - offset.y
}
}

Expand All @@ -1548,6 +1571,13 @@ function normalizePosition (obj) {
}
}

function normalizeOffset (obj) {
return {
x: isNumber(obj.x) ? obj.x : 0,
y: isNumber(obj.y) ? obj.y : 0
}
}

function isNumber (v) {
return typeof v === 'number'
}
Expand Down Expand Up @@ -1800,6 +1830,8 @@ function normalizeBase (base) {
// respect <base> tag
var baseEl = document.querySelector('base');
base = (baseEl && baseEl.getAttribute('href')) || '/';
// strip full URL origin
base = base.replace(/^https?:\/\/[^\/]+/, '');
} else {
base = '/';
}
Expand Down Expand Up @@ -2010,9 +2042,12 @@ function flatten (arr) {
function once (fn) {
var called = false;
return function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];

if (called) { return }
called = true;
return fn.apply(this, arguments)
return fn.apply(this, args)
}
}

Expand All @@ -2036,9 +2071,10 @@ var HTML5History = (function (History$$1) {
}

window.addEventListener('popstate', function (e) {
var current = this$1.current;
this$1.transitionTo(getLocation(this$1.base), function (route) {
if (expectScroll) {
handleScroll(router, route, this$1.current, true);
handleScroll(router, route, current, true);
}
});
});
Expand Down Expand Up @@ -2194,10 +2230,10 @@ function pushHash (path) {
}

function replaceHash (path) {
var i = window.location.href.indexOf('#');
window.location.replace(
window.location.href.slice(0, i >= 0 ? i : 0) + '#' + path
);
var href = window.location.href;
var i = href.indexOf('#');
var base = i >= 0 ? href.slice(0, i) : href;
window.location.replace((base + "#" + path));
}

/* */
Expand Down Expand Up @@ -2273,7 +2309,7 @@ var VueRouter = function VueRouter (options) {
this.matcher = createMatcher(options.routes || [], this);

var mode = options.mode || 'hash';
this.fallback = mode === 'history' && !supportsPushState;
this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false;
if (this.fallback) {
mode = 'hash';
}
Expand Down Expand Up @@ -2457,7 +2493,7 @@ function createHref (base, fullPath, mode) {
}

VueRouter.install = install;
VueRouter.version = '2.5.3';
VueRouter.version = '2.6.0';

if (inBrowser && window.Vue) {
window.Vue.use(VueRouter);
Expand Down
Loading

0 comments on commit a329938

Please sign in to comment.