Skip to content

Commit 9d3f10f

Browse files
committed
[build] 0.7.10
1 parent 2160fc9 commit 9d3f10f

File tree

2 files changed

+93
-60
lines changed

2 files changed

+93
-60
lines changed

dist/vue-router.js

Lines changed: 91 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-router v0.7.9
2+
* vue-router v0.7.10
33
* (c) 2016 Evan You
44
* Released under the MIT License.
55
*/
@@ -182,7 +182,8 @@
182182
},
183183

184184
generate: function generate(params) {
185-
return params[this.name] || ":" + this.name;
185+
var val = params[this.name];
186+
return val == null ? ":" + this.name : val;
186187
}
187188
};
188189

@@ -199,7 +200,8 @@
199200
},
200201

201202
generate: function generate(params) {
202-
return params[this.name] || ":" + this.name;
203+
var val = params[this.name];
204+
return val == null ? ":" + this.name : val;
203205
}
204206
};
205207

@@ -1118,7 +1120,7 @@
11181120
function activate(view, transition, depth, cb, reuse) {
11191121
var handler = transition.activateQueue[depth];
11201122
if (!handler) {
1121-
// fix 1.0.0-alpha.3 compat
1123+
saveChildView(view);
11221124
if (view._bound) {
11231125
view.setComponent(null);
11241126
}
@@ -1148,16 +1150,12 @@
11481150
component = view.childVM;
11491151
component.$loadingRouteData = loading;
11501152
} else {
1153+
saveChildView(view);
1154+
11511155
// unbuild current component. this step also destroys
11521156
// and removes all nested child views.
11531157
view.unbuild(true);
11541158

1155-
// handle keep-alive.
1156-
// cache the child view on the kept-alive child vm.
1157-
if (view.keepAlive && view.childVM && view.childView) {
1158-
view.childVM._keepAliveRouterView = view.childView;
1159-
}
1160-
11611159
// build the new component. this will also create the
11621160
// direct child view of the current one. it will register
11631161
// itself as view.childView.
@@ -1214,29 +1212,31 @@
12141212
cb && cb();
12151213
};
12161214

1217-
// called after activation hook is resolved
1218-
var afterActivate = function afterActivate() {
1219-
view.activated = true;
1215+
var afterData = function afterData() {
12201216
// activate the child view
12211217
if (view.childView) {
12221218
activate(view.childView, transition, depth + 1, null, reuse || view.keepAlive);
12231219
}
1220+
insert();
1221+
};
1222+
1223+
// called after activation hook is resolved
1224+
var afterActivate = function afterActivate() {
1225+
view.activated = true;
12241226
if (dataHook && waitForData) {
12251227
// wait until data loaded to insert
1226-
loadData(component, transition, dataHook, insert, cleanup);
1228+
loadData(component, transition, dataHook, afterData, cleanup);
12271229
} else {
12281230
// load data and insert at the same time
12291231
if (dataHook) {
12301232
loadData(component, transition, dataHook);
12311233
}
1232-
insert();
1234+
afterData();
12331235
}
12341236
};
12351237

12361238
if (activateHook) {
1237-
transition.callHooks(activateHook, component, afterActivate, {
1238-
cleanup: cleanup
1239-
});
1239+
transition.callHooks(activateHook, component, afterActivate, { cleanup: cleanup });
12401240
} else {
12411241
afterActivate();
12421242
}
@@ -1300,7 +1300,7 @@
13001300
component.$emit('route-data-loaded', component);
13011301
cb && cb();
13021302
} else {
1303-
promises[0].constructor.all(promises).then(function (_) {
1303+
promises[0].constructor.all(promises).then(function () {
13041304
component.$loadingRouteData = false;
13051305
component.$emit('route-data-loaded', component);
13061306
cb && cb();
@@ -1312,8 +1312,28 @@
13121312
});
13131313
}
13141314

1315-
function isPlainObject(obj) {
1316-
return Object.prototype.toString.call(obj) === '[object Object]';
1315+
/**
1316+
* Save the child view for a kept-alive view so that
1317+
* we can restore it when it is switched back to.
1318+
*
1319+
* @param {Directive} view
1320+
*/
1321+
1322+
function saveChildView(view) {
1323+
if (view.keepAlive && view.childVM && view.childView) {
1324+
view.childVM._keepAliveRouterView = view.childView;
1325+
}
1326+
view.childView = null;
1327+
}
1328+
1329+
/**
1330+
* Check plain object.
1331+
*
1332+
* @param {*} val
1333+
*/
1334+
1335+
function isPlainObject(val) {
1336+
return Object.prototype.toString.call(val) === '[object Object]';
13171337
}
13181338

13191339
/**
@@ -1706,12 +1726,10 @@
17061726

17071727
var destroy = Vue.prototype._destroy;
17081728
Vue.prototype._destroy = function () {
1709-
if (!this._isBeingDestroyed) {
1710-
if (this.$router) {
1711-
this.$router._children.$remove(this);
1712-
}
1713-
destroy.apply(this, arguments);
1729+
if (!this._isBeingDestroyed && this.$router) {
1730+
this.$router._children.$remove(this);
17141731
}
1732+
destroy.apply(this, arguments);
17151733
};
17161734

17171735
// 1.0 only: enable route mixins
@@ -1849,14 +1867,6 @@
18491867
this.router = vm.$route.router;
18501868
// update things when the route changes
18511869
this.unwatch = vm.$watch('$route', _bind(this.onRouteUpdate, this));
1852-
// no need to handle click if link expects to be opened
1853-
// in a new window/tab.
1854-
/* istanbul ignore if */
1855-
if (this.el.tagName === 'A' && this.el.getAttribute('target') === '_blank') {
1856-
return;
1857-
}
1858-
// handle click
1859-
this.el.addEventListener('click', _bind(this.onClick, this));
18601870
// check if active classes should be applied to a different element
18611871
this.activeEl = this.el;
18621872
var parent = this.el.parentNode;
@@ -1867,6 +1877,14 @@
18671877
}
18681878
parent = parent.parentNode;
18691879
}
1880+
// no need to handle click if link expects to be opened
1881+
// in a new window/tab.
1882+
/* istanbul ignore if */
1883+
if (this.el.tagName === 'A' && this.el.getAttribute('target') === '_blank') {
1884+
return;
1885+
}
1886+
// handle click
1887+
this.el.addEventListener('click', _bind(this.onClick, this));
18701888
},
18711889

18721890
update: function update(target) {
@@ -2001,6 +2019,8 @@
20012019

20022020
var Router = (function () {
20032021
function Router() {
2022+
var _this = this;
2023+
20042024
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
20052025

20062026
var _ref$hashbang = _ref.hashbang;
@@ -2045,36 +2065,37 @@
20452065
this._beforeEachHooks = [];
20462066
this._afterEachHooks = [];
20472067

2048-
// feature detection
2049-
this._hasPushState = typeof window !== 'undefined' && window.history && window.history.pushState;
2050-
20512068
// trigger transition on initial render?
20522069
this._rendered = false;
20532070
this._transitionOnLoad = transitionOnLoad;
20542071

20552072
// history mode
2073+
this._root = root;
20562074
this._abstract = abstract;
20572075
this._hashbang = hashbang;
2058-
this._history = this._hasPushState && history;
20592076

2060-
// other options
2061-
this._saveScrollPosition = saveScrollPosition;
2062-
this._linkActiveClass = linkActiveClass;
2063-
this._suppress = suppressTransitionError;
2077+
// check if HTML5 history is available
2078+
var hasPushState = typeof window !== 'undefined' && window.history && window.history.pushState;
2079+
this._history = history && hasPushState;
2080+
this._historyFallback = history && !hasPushState;
20642081

20652082
// create history object
20662083
var inBrowser = Vue.util.inBrowser;
20672084
this.mode = !inBrowser || this._abstract ? 'abstract' : this._history ? 'html5' : 'hash';
20682085

20692086
var History = historyBackends[this.mode];
2070-
var self = this;
20712087
this.history = new History({
20722088
root: root,
20732089
hashbang: this._hashbang,
20742090
onChange: function onChange(path, state, anchor) {
2075-
self._match(path, state, anchor);
2091+
_this._match(path, state, anchor);
20762092
}
20772093
});
2094+
2095+
// other options
2096+
this._saveScrollPosition = saveScrollPosition;
2097+
this._linkActiveClass = linkActiveClass;
2098+
this._suppress = suppressTransitionError;
20782099
}
20792100

20802101
/**
@@ -2237,6 +2258,19 @@
22372258
// give it a name for better debugging
22382259
Ctor.options.name = Ctor.options.name || 'RouterApp';
22392260
}
2261+
2262+
// handle history fallback in browsers that do not
2263+
// support HTML5 history API
2264+
if (this._historyFallback) {
2265+
var _location = window.location;
2266+
var _history = new HTML5History({ root: this._root });
2267+
var path = _history.root ? _location.pathname.replace(_history.rootRE, '') : _location.pathname;
2268+
if (path && path !== '/') {
2269+
_location.assign((_history.root || '') + '/' + this.history.formatPath(path) + _location.search);
2270+
return;
2271+
}
2272+
}
2273+
22402274
this.history.start();
22412275
};
22422276

@@ -2332,13 +2366,13 @@
23322366
*/
23332367

23342368
Router.prototype._addGuard = function _addGuard(path, mappedPath, _handler) {
2335-
var _this = this;
2369+
var _this2 = this;
23362370

23372371
this._guardRecognizer.add([{
23382372
path: path,
23392373
handler: function handler(match, query) {
23402374
var realPath = mapParams(mappedPath, match.params, query);
2341-
_handler.call(_this, realPath);
2375+
_handler.call(_this2, realPath);
23422376
}
23432377
}]);
23442378
};
@@ -2374,7 +2408,7 @@
23742408
*/
23752409

23762410
Router.prototype._match = function _match(path, state, anchor) {
2377-
var _this2 = this;
2411+
var _this3 = this;
23782412

23792413
if (this._checkGuard(path)) {
23802414
return;
@@ -2413,9 +2447,9 @@
24132447
if (!this.app) {
24142448
(function () {
24152449
// initial render
2416-
var router = _this2;
2417-
_this2.app = new _this2._appConstructor({
2418-
el: _this2._appContainer,
2450+
var router = _this3;
2451+
_this3.app = new _this3._appConstructor({
2452+
el: _this3._appContainer,
24192453
created: function created() {
24202454
this.$router = router;
24212455
},
@@ -2430,13 +2464,13 @@
24302464
var beforeHooks = this._beforeEachHooks;
24312465
var startTransition = function startTransition() {
24322466
transition.start(function () {
2433-
_this2._postTransition(route, state, anchor);
2467+
_this3._postTransition(route, state, anchor);
24342468
});
24352469
};
24362470

24372471
if (beforeHooks.length) {
24382472
transition.runQueue(beforeHooks, function (hook, _, next) {
2439-
if (transition === _this2._currentTransition) {
2473+
if (transition === _this3._currentTransition) {
24402474
transition.callHook(hook, null, next, {
24412475
expectBoolean: true
24422476
});
@@ -2523,6 +2557,7 @@
25232557
*/
25242558

25252559
Router.prototype._stringifyPath = function _stringifyPath(path) {
2560+
var fullPath = '';
25262561
if (path && typeof path === 'object') {
25272562
if (path.name) {
25282563
var extend = Vue.util.extend;
@@ -2532,9 +2567,9 @@
25322567
if (path.query) {
25332568
params.queryParams = path.query;
25342569
}
2535-
return this._recognizer.generate(path.name, params);
2570+
fullPath = this._recognizer.generate(path.name, params);
25362571
} else if (path.path) {
2537-
var fullPath = path.path;
2572+
fullPath = path.path;
25382573
if (path.query) {
25392574
var query = this._recognizer.generateQueryString(path.query);
25402575
if (fullPath.indexOf('?') > -1) {
@@ -2543,13 +2578,11 @@
25432578
fullPath += query;
25442579
}
25452580
}
2546-
return fullPath;
2547-
} else {
2548-
return '';
25492581
}
25502582
} else {
2551-
return path ? path + '' : '';
2583+
fullPath = path ? path + '' : '';
25522584
}
2585+
return encodeURI(fullPath);
25532586
};
25542587

25552588
return Router;

0 commit comments

Comments
 (0)