vuejs-rails 0.12.12 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +2 -0
- data/lib/vuejs-rails/version.rb +1 -1
- data/vendor/assets/javascripts/vue-resource.js +968 -0
- data/vendor/assets/javascripts/vue-router.js +2997 -0
- data/vendor/assets/javascripts/vue.js +6243 -5927
- metadata +5 -2
@@ -0,0 +1,2997 @@
|
|
1
|
+
/*!
|
2
|
+
* vue-router v0.7.5
|
3
|
+
* (c) 2015 Evan You
|
4
|
+
* Released under the MIT License.
|
5
|
+
*/
|
6
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
7
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
8
|
+
module.exports = factory();
|
9
|
+
else if(typeof define === 'function' && define.amd)
|
10
|
+
define([], factory);
|
11
|
+
else if(typeof exports === 'object')
|
12
|
+
exports["VueRouter"] = factory();
|
13
|
+
else
|
14
|
+
root["VueRouter"] = factory();
|
15
|
+
})(this, function() {
|
16
|
+
return /******/ (function(modules) { // webpackBootstrap
|
17
|
+
/******/ // The module cache
|
18
|
+
/******/ var installedModules = {};
|
19
|
+
|
20
|
+
/******/ // The require function
|
21
|
+
/******/ function __webpack_require__(moduleId) {
|
22
|
+
|
23
|
+
/******/ // Check if module is in cache
|
24
|
+
/******/ if(installedModules[moduleId])
|
25
|
+
/******/ return installedModules[moduleId].exports;
|
26
|
+
|
27
|
+
/******/ // Create a new module (and put it into the cache)
|
28
|
+
/******/ var module = installedModules[moduleId] = {
|
29
|
+
/******/ exports: {},
|
30
|
+
/******/ id: moduleId,
|
31
|
+
/******/ loaded: false
|
32
|
+
/******/ };
|
33
|
+
|
34
|
+
/******/ // Execute the module function
|
35
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
36
|
+
|
37
|
+
/******/ // Flag the module as loaded
|
38
|
+
/******/ module.loaded = true;
|
39
|
+
|
40
|
+
/******/ // Return the exports of the module
|
41
|
+
/******/ return module.exports;
|
42
|
+
/******/ }
|
43
|
+
|
44
|
+
|
45
|
+
/******/ // expose the modules object (__webpack_modules__)
|
46
|
+
/******/ __webpack_require__.m = modules;
|
47
|
+
|
48
|
+
/******/ // expose the module cache
|
49
|
+
/******/ __webpack_require__.c = installedModules;
|
50
|
+
|
51
|
+
/******/ // __webpack_public_path__
|
52
|
+
/******/ __webpack_require__.p = "";
|
53
|
+
|
54
|
+
/******/ // Load entry module and return exports
|
55
|
+
/******/ return __webpack_require__(0);
|
56
|
+
/******/ })
|
57
|
+
/************************************************************************/
|
58
|
+
/******/ ([
|
59
|
+
/* 0 */
|
60
|
+
/***/ function(module, exports, __webpack_require__) {
|
61
|
+
|
62
|
+
'use strict';
|
63
|
+
|
64
|
+
var _classCallCheck = __webpack_require__(1)['default'];
|
65
|
+
|
66
|
+
var _interopRequireDefault = __webpack_require__(2)['default'];
|
67
|
+
|
68
|
+
exports.__esModule = true;
|
69
|
+
|
70
|
+
var _util = __webpack_require__(3);
|
71
|
+
|
72
|
+
var _util2 = _interopRequireDefault(_util);
|
73
|
+
|
74
|
+
var _override = __webpack_require__(7);
|
75
|
+
|
76
|
+
var _override2 = _interopRequireDefault(_override);
|
77
|
+
|
78
|
+
var _routeRecognizer = __webpack_require__(4);
|
79
|
+
|
80
|
+
var _routeRecognizer2 = _interopRequireDefault(_routeRecognizer);
|
81
|
+
|
82
|
+
var _route = __webpack_require__(8);
|
83
|
+
|
84
|
+
var _route2 = _interopRequireDefault(_route);
|
85
|
+
|
86
|
+
var _transition = __webpack_require__(18);
|
87
|
+
|
88
|
+
var _transition2 = _interopRequireDefault(_transition);
|
89
|
+
|
90
|
+
var _directivesView = __webpack_require__(28);
|
91
|
+
|
92
|
+
var _directivesView2 = _interopRequireDefault(_directivesView);
|
93
|
+
|
94
|
+
var _directivesLink = __webpack_require__(29);
|
95
|
+
|
96
|
+
var _directivesLink2 = _interopRequireDefault(_directivesLink);
|
97
|
+
|
98
|
+
var _historyAbstract = __webpack_require__(30);
|
99
|
+
|
100
|
+
var _historyAbstract2 = _interopRequireDefault(_historyAbstract);
|
101
|
+
|
102
|
+
var _historyHash = __webpack_require__(31);
|
103
|
+
|
104
|
+
var _historyHash2 = _interopRequireDefault(_historyHash);
|
105
|
+
|
106
|
+
var _historyHtml5 = __webpack_require__(32);
|
107
|
+
|
108
|
+
var _historyHtml52 = _interopRequireDefault(_historyHtml5);
|
109
|
+
|
110
|
+
var historyBackends = {
|
111
|
+
abstract: _historyAbstract2['default'],
|
112
|
+
hash: _historyHash2['default'],
|
113
|
+
html5: _historyHtml52['default']
|
114
|
+
};
|
115
|
+
|
116
|
+
// late bind during install
|
117
|
+
var Vue = undefined;
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Router constructor
|
121
|
+
*
|
122
|
+
* @param {Object} [options]
|
123
|
+
*/
|
124
|
+
|
125
|
+
var Router = (function () {
|
126
|
+
function Router() {
|
127
|
+
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
128
|
+
|
129
|
+
var _ref$hashbang = _ref.hashbang;
|
130
|
+
var hashbang = _ref$hashbang === undefined ? true : _ref$hashbang;
|
131
|
+
var _ref$abstract = _ref.abstract;
|
132
|
+
var abstract = _ref$abstract === undefined ? false : _ref$abstract;
|
133
|
+
var _ref$history = _ref.history;
|
134
|
+
var history = _ref$history === undefined ? false : _ref$history;
|
135
|
+
var _ref$saveScrollPosition = _ref.saveScrollPosition;
|
136
|
+
var saveScrollPosition = _ref$saveScrollPosition === undefined ? false : _ref$saveScrollPosition;
|
137
|
+
var _ref$transitionOnLoad = _ref.transitionOnLoad;
|
138
|
+
var transitionOnLoad = _ref$transitionOnLoad === undefined ? false : _ref$transitionOnLoad;
|
139
|
+
var _ref$suppressTransitionError = _ref.suppressTransitionError;
|
140
|
+
var suppressTransitionError = _ref$suppressTransitionError === undefined ? false : _ref$suppressTransitionError;
|
141
|
+
var _ref$root = _ref.root;
|
142
|
+
var root = _ref$root === undefined ? null : _ref$root;
|
143
|
+
var _ref$linkActiveClass = _ref.linkActiveClass;
|
144
|
+
var linkActiveClass = _ref$linkActiveClass === undefined ? 'v-link-active' : _ref$linkActiveClass;
|
145
|
+
|
146
|
+
_classCallCheck(this, Router);
|
147
|
+
|
148
|
+
/* istanbul ignore if */
|
149
|
+
if (!Router.installed) {
|
150
|
+
throw new Error('Please install the Router with Vue.use() before ' + 'creating an instance.');
|
151
|
+
}
|
152
|
+
|
153
|
+
// Vue instances
|
154
|
+
this.app = null;
|
155
|
+
this._views = [];
|
156
|
+
this._children = [];
|
157
|
+
|
158
|
+
// route recognizer
|
159
|
+
this._recognizer = new _routeRecognizer2['default']();
|
160
|
+
this._guardRecognizer = new _routeRecognizer2['default']();
|
161
|
+
|
162
|
+
// state
|
163
|
+
this._started = false;
|
164
|
+
this._startCb = null;
|
165
|
+
this._currentRoute = {};
|
166
|
+
this._currentTransition = null;
|
167
|
+
this._previousTransition = null;
|
168
|
+
this._notFoundHandler = null;
|
169
|
+
this._notFoundRedirect = null;
|
170
|
+
this._beforeEachHooks = [];
|
171
|
+
this._afterEachHooks = [];
|
172
|
+
|
173
|
+
// feature detection
|
174
|
+
this._hasPushState = typeof window !== 'undefined' && window.history && window.history.pushState;
|
175
|
+
|
176
|
+
// trigger transition on initial render?
|
177
|
+
this._rendered = false;
|
178
|
+
this._transitionOnLoad = transitionOnLoad;
|
179
|
+
|
180
|
+
// history mode
|
181
|
+
this._abstract = abstract;
|
182
|
+
this._hashbang = hashbang;
|
183
|
+
this._history = this._hasPushState && history;
|
184
|
+
|
185
|
+
// other options
|
186
|
+
this._saveScrollPosition = saveScrollPosition;
|
187
|
+
this._linkActiveClass = linkActiveClass;
|
188
|
+
this._suppress = suppressTransitionError;
|
189
|
+
|
190
|
+
// create history object
|
191
|
+
var inBrowser = Vue.util.inBrowser;
|
192
|
+
this.mode = !inBrowser || this._abstract ? 'abstract' : this._history ? 'html5' : 'hash';
|
193
|
+
|
194
|
+
var History = historyBackends[this.mode];
|
195
|
+
var self = this;
|
196
|
+
this.history = new History({
|
197
|
+
root: root,
|
198
|
+
hashbang: this._hashbang,
|
199
|
+
onChange: function onChange(path, state, anchor) {
|
200
|
+
self._match(path, state, anchor);
|
201
|
+
}
|
202
|
+
});
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* Allow directly passing components to a route
|
207
|
+
* definition.
|
208
|
+
*
|
209
|
+
* @param {String} path
|
210
|
+
* @param {Object} handler
|
211
|
+
*/
|
212
|
+
|
213
|
+
// API ===================================================
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Register a map of top-level paths.
|
217
|
+
*
|
218
|
+
* @param {Object} map
|
219
|
+
*/
|
220
|
+
|
221
|
+
Router.prototype.map = function map(_map) {
|
222
|
+
for (var route in _map) {
|
223
|
+
this.on(route, _map[route]);
|
224
|
+
}
|
225
|
+
};
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Register a single root-level path
|
229
|
+
*
|
230
|
+
* @param {String} rootPath
|
231
|
+
* @param {Object} handler
|
232
|
+
* - {String} component
|
233
|
+
* - {Object} [subRoutes]
|
234
|
+
* - {Boolean} [forceRefresh]
|
235
|
+
* - {Function} [before]
|
236
|
+
* - {Function} [after]
|
237
|
+
*/
|
238
|
+
|
239
|
+
Router.prototype.on = function on(rootPath, handler) {
|
240
|
+
if (rootPath === '*') {
|
241
|
+
this._notFound(handler);
|
242
|
+
} else {
|
243
|
+
this._addRoute(rootPath, handler, []);
|
244
|
+
}
|
245
|
+
};
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Set redirects.
|
249
|
+
*
|
250
|
+
* @param {Object} map
|
251
|
+
*/
|
252
|
+
|
253
|
+
Router.prototype.redirect = function redirect(map) {
|
254
|
+
for (var path in map) {
|
255
|
+
this._addRedirect(path, map[path]);
|
256
|
+
}
|
257
|
+
};
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Set aliases.
|
261
|
+
*
|
262
|
+
* @param {Object} map
|
263
|
+
*/
|
264
|
+
|
265
|
+
Router.prototype.alias = function alias(map) {
|
266
|
+
for (var path in map) {
|
267
|
+
this._addAlias(path, map[path]);
|
268
|
+
}
|
269
|
+
};
|
270
|
+
|
271
|
+
/**
|
272
|
+
* Set global before hook.
|
273
|
+
*
|
274
|
+
* @param {Function} fn
|
275
|
+
*/
|
276
|
+
|
277
|
+
Router.prototype.beforeEach = function beforeEach(fn) {
|
278
|
+
this._beforeEachHooks.push(fn);
|
279
|
+
};
|
280
|
+
|
281
|
+
/**
|
282
|
+
* Set global after hook.
|
283
|
+
*
|
284
|
+
* @param {Function} fn
|
285
|
+
*/
|
286
|
+
|
287
|
+
Router.prototype.afterEach = function afterEach(fn) {
|
288
|
+
this._afterEachHooks.push(fn);
|
289
|
+
};
|
290
|
+
|
291
|
+
/**
|
292
|
+
* Navigate to a given path.
|
293
|
+
* The path can be an object describing a named path in
|
294
|
+
* the format of { name: '...', params: {}, query: {}}
|
295
|
+
* The path is assumed to be already decoded, and will
|
296
|
+
* be resolved against root (if provided)
|
297
|
+
*
|
298
|
+
* @param {String|Object} path
|
299
|
+
* @param {Boolean} [replace]
|
300
|
+
*/
|
301
|
+
|
302
|
+
Router.prototype.go = function go(path) {
|
303
|
+
var replace = false;
|
304
|
+
var append = false;
|
305
|
+
if (Vue.util.isObject(path)) {
|
306
|
+
replace = path.replace;
|
307
|
+
append = path.append;
|
308
|
+
}
|
309
|
+
path = this._stringifyPath(path);
|
310
|
+
if (path) {
|
311
|
+
this.history.go(path, replace, append);
|
312
|
+
}
|
313
|
+
};
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Short hand for replacing current path
|
317
|
+
*
|
318
|
+
* @param {String} path
|
319
|
+
*/
|
320
|
+
|
321
|
+
Router.prototype.replace = function replace(path) {
|
322
|
+
this.go({ path: path, replace: true });
|
323
|
+
};
|
324
|
+
|
325
|
+
/**
|
326
|
+
* Start the router.
|
327
|
+
*
|
328
|
+
* @param {VueConstructor} App
|
329
|
+
* @param {String|Element} container
|
330
|
+
* @param {Function} [cb]
|
331
|
+
*/
|
332
|
+
|
333
|
+
Router.prototype.start = function start(App, container, cb) {
|
334
|
+
/* istanbul ignore if */
|
335
|
+
if (this._started) {
|
336
|
+
_util.warn('already started.');
|
337
|
+
return;
|
338
|
+
}
|
339
|
+
this._started = true;
|
340
|
+
this._startCb = cb;
|
341
|
+
if (!this.app) {
|
342
|
+
/* istanbul ignore if */
|
343
|
+
if (!App || !container) {
|
344
|
+
throw new Error('Must start vue-router with a component and a ' + 'root container.');
|
345
|
+
}
|
346
|
+
this._appContainer = container;
|
347
|
+
var Ctor = this._appConstructor = typeof App === 'function' ? App : Vue.extend(App);
|
348
|
+
// give it a name for better debugging
|
349
|
+
Ctor.options.name = Ctor.options.name || 'RouterApp';
|
350
|
+
}
|
351
|
+
this.history.start();
|
352
|
+
};
|
353
|
+
|
354
|
+
/**
|
355
|
+
* Stop listening to route changes.
|
356
|
+
*/
|
357
|
+
|
358
|
+
Router.prototype.stop = function stop() {
|
359
|
+
this.history.stop();
|
360
|
+
this._started = false;
|
361
|
+
};
|
362
|
+
|
363
|
+
// Internal methods ======================================
|
364
|
+
|
365
|
+
/**
|
366
|
+
* Add a route containing a list of segments to the internal
|
367
|
+
* route recognizer. Will be called recursively to add all
|
368
|
+
* possible sub-routes.
|
369
|
+
*
|
370
|
+
* @param {String} path
|
371
|
+
* @param {Object} handler
|
372
|
+
* @param {Array} segments
|
373
|
+
*/
|
374
|
+
|
375
|
+
Router.prototype._addRoute = function _addRoute(path, handler, segments) {
|
376
|
+
guardComponent(path, handler);
|
377
|
+
handler.path = path;
|
378
|
+
handler.fullPath = (segments.reduce(function (path, segment) {
|
379
|
+
return path + segment.path;
|
380
|
+
}, '') + path).replace('//', '/');
|
381
|
+
segments.push({
|
382
|
+
path: path,
|
383
|
+
handler: handler
|
384
|
+
});
|
385
|
+
this._recognizer.add(segments, {
|
386
|
+
as: handler.name
|
387
|
+
});
|
388
|
+
// add sub routes
|
389
|
+
if (handler.subRoutes) {
|
390
|
+
for (var subPath in handler.subRoutes) {
|
391
|
+
// recursively walk all sub routes
|
392
|
+
this._addRoute(subPath, handler.subRoutes[subPath],
|
393
|
+
// pass a copy in recursion to avoid mutating
|
394
|
+
// across branches
|
395
|
+
segments.slice());
|
396
|
+
}
|
397
|
+
}
|
398
|
+
};
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Set the notFound route handler.
|
402
|
+
*
|
403
|
+
* @param {Object} handler
|
404
|
+
*/
|
405
|
+
|
406
|
+
Router.prototype._notFound = function _notFound(handler) {
|
407
|
+
guardComponent('*', handler);
|
408
|
+
this._notFoundHandler = [{ handler: handler }];
|
409
|
+
};
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Add a redirect record.
|
413
|
+
*
|
414
|
+
* @param {String} path
|
415
|
+
* @param {String} redirectPath
|
416
|
+
*/
|
417
|
+
|
418
|
+
Router.prototype._addRedirect = function _addRedirect(path, redirectPath) {
|
419
|
+
if (path === '*') {
|
420
|
+
this._notFoundRedirect = redirectPath;
|
421
|
+
} else {
|
422
|
+
this._addGuard(path, redirectPath, this.replace);
|
423
|
+
}
|
424
|
+
};
|
425
|
+
|
426
|
+
/**
|
427
|
+
* Add an alias record.
|
428
|
+
*
|
429
|
+
* @param {String} path
|
430
|
+
* @param {String} aliasPath
|
431
|
+
*/
|
432
|
+
|
433
|
+
Router.prototype._addAlias = function _addAlias(path, aliasPath) {
|
434
|
+
this._addGuard(path, aliasPath, this._match);
|
435
|
+
};
|
436
|
+
|
437
|
+
/**
|
438
|
+
* Add a path guard.
|
439
|
+
*
|
440
|
+
* @param {String} path
|
441
|
+
* @param {String} mappedPath
|
442
|
+
* @param {Function} handler
|
443
|
+
*/
|
444
|
+
|
445
|
+
Router.prototype._addGuard = function _addGuard(path, mappedPath, _handler) {
|
446
|
+
var _this = this;
|
447
|
+
|
448
|
+
this._guardRecognizer.add([{
|
449
|
+
path: path,
|
450
|
+
handler: function handler(match, query) {
|
451
|
+
var realPath = _util.mapParams(mappedPath, match.params, query);
|
452
|
+
_handler.call(_this, realPath);
|
453
|
+
}
|
454
|
+
}]);
|
455
|
+
};
|
456
|
+
|
457
|
+
/**
|
458
|
+
* Check if a path matches any redirect records.
|
459
|
+
*
|
460
|
+
* @param {String} path
|
461
|
+
* @return {Boolean} - if true, will skip normal match.
|
462
|
+
*/
|
463
|
+
|
464
|
+
Router.prototype._checkGuard = function _checkGuard(path) {
|
465
|
+
var matched = this._guardRecognizer.recognize(path);
|
466
|
+
if (matched) {
|
467
|
+
matched[0].handler(matched[0], matched.queryParams);
|
468
|
+
return true;
|
469
|
+
} else if (this._notFoundRedirect) {
|
470
|
+
matched = this._recognizer.recognize(path);
|
471
|
+
if (!matched) {
|
472
|
+
this.replace(this._notFoundRedirect);
|
473
|
+
return true;
|
474
|
+
}
|
475
|
+
}
|
476
|
+
};
|
477
|
+
|
478
|
+
/**
|
479
|
+
* Match a URL path and set the route context on vm,
|
480
|
+
* triggering view updates.
|
481
|
+
*
|
482
|
+
* @param {String} path
|
483
|
+
* @param {Object} [state]
|
484
|
+
* @param {String} [anchor]
|
485
|
+
*/
|
486
|
+
|
487
|
+
Router.prototype._match = function _match(path, state, anchor) {
|
488
|
+
var _this2 = this;
|
489
|
+
|
490
|
+
if (this._checkGuard(path)) {
|
491
|
+
return;
|
492
|
+
}
|
493
|
+
|
494
|
+
var currentRoute = this._currentRoute;
|
495
|
+
var currentTransition = this._currentTransition;
|
496
|
+
|
497
|
+
if (currentTransition) {
|
498
|
+
if (currentTransition.to.path === path) {
|
499
|
+
// do nothing if we have an active transition going to the same path
|
500
|
+
return;
|
501
|
+
} else if (currentRoute.path === path) {
|
502
|
+
// We are going to the same path, but we also have an ongoing but
|
503
|
+
// not-yet-validated transition. Abort that transition and reset to
|
504
|
+
// prev transition.
|
505
|
+
currentTransition.aborted = true;
|
506
|
+
this._currentTransition = this._prevTransition;
|
507
|
+
return;
|
508
|
+
} else {
|
509
|
+
// going to a totally different path. abort ongoing transition.
|
510
|
+
currentTransition.aborted = true;
|
511
|
+
}
|
512
|
+
}
|
513
|
+
|
514
|
+
// construct new route and transition context
|
515
|
+
var route = new _route2['default'](path, this);
|
516
|
+
var transition = new _transition2['default'](this, route, currentRoute);
|
517
|
+
|
518
|
+
// current transition is updated right now.
|
519
|
+
// however, current route will only be updated after the transition has
|
520
|
+
// been validated.
|
521
|
+
this._prevTransition = currentTransition;
|
522
|
+
this._currentTransition = transition;
|
523
|
+
|
524
|
+
if (!this.app) {
|
525
|
+
// initial render
|
526
|
+
this.app = new this._appConstructor({
|
527
|
+
el: this._appContainer,
|
528
|
+
_meta: {
|
529
|
+
$route: route
|
530
|
+
}
|
531
|
+
});
|
532
|
+
}
|
533
|
+
|
534
|
+
// check global before hook
|
535
|
+
var beforeHooks = this._beforeEachHooks;
|
536
|
+
var startTransition = function startTransition() {
|
537
|
+
transition.start(function () {
|
538
|
+
_this2._postTransition(route, state, anchor);
|
539
|
+
});
|
540
|
+
};
|
541
|
+
|
542
|
+
if (beforeHooks.length) {
|
543
|
+
transition.runQueue(beforeHooks, function (hook, _, next) {
|
544
|
+
if (transition === _this2._currentTransition) {
|
545
|
+
transition.callHook(hook, null, next, {
|
546
|
+
expectBoolean: true
|
547
|
+
});
|
548
|
+
}
|
549
|
+
}, startTransition);
|
550
|
+
} else {
|
551
|
+
startTransition();
|
552
|
+
}
|
553
|
+
|
554
|
+
if (!this._rendered && this._startCb) {
|
555
|
+
this._startCb.call(null);
|
556
|
+
}
|
557
|
+
|
558
|
+
// HACK:
|
559
|
+
// set rendered to true after the transition start, so
|
560
|
+
// that components that are acitvated synchronously know
|
561
|
+
// whether it is the initial render.
|
562
|
+
this._rendered = true;
|
563
|
+
};
|
564
|
+
|
565
|
+
/**
|
566
|
+
* Set current to the new transition.
|
567
|
+
* This is called by the transition object when the
|
568
|
+
* validation of a route has succeeded.
|
569
|
+
*
|
570
|
+
* @param {Transition} transition
|
571
|
+
*/
|
572
|
+
|
573
|
+
Router.prototype._onTransitionValidated = function _onTransitionValidated(transition) {
|
574
|
+
// set current route
|
575
|
+
var route = this._currentRoute = transition.to;
|
576
|
+
// update route context for all children
|
577
|
+
if (this.app.$route !== route) {
|
578
|
+
this.app.$route = route;
|
579
|
+
this._children.forEach(function (child) {
|
580
|
+
child.$route = route;
|
581
|
+
});
|
582
|
+
}
|
583
|
+
// call global after hook
|
584
|
+
if (this._afterEachHooks.length) {
|
585
|
+
this._afterEachHooks.forEach(function (hook) {
|
586
|
+
return hook.call(null, {
|
587
|
+
to: transition.to,
|
588
|
+
from: transition.from
|
589
|
+
});
|
590
|
+
});
|
591
|
+
}
|
592
|
+
this._currentTransition.done = true;
|
593
|
+
};
|
594
|
+
|
595
|
+
/**
|
596
|
+
* Handle stuff after the transition.
|
597
|
+
*
|
598
|
+
* @param {Route} route
|
599
|
+
* @param {Object} [state]
|
600
|
+
* @param {String} [anchor]
|
601
|
+
*/
|
602
|
+
|
603
|
+
Router.prototype._postTransition = function _postTransition(route, state, anchor) {
|
604
|
+
// handle scroll positions
|
605
|
+
// saved scroll positions take priority
|
606
|
+
// then we check if the path has an anchor
|
607
|
+
var pos = state && state.pos;
|
608
|
+
if (pos && this._saveScrollPosition) {
|
609
|
+
Vue.nextTick(function () {
|
610
|
+
window.scrollTo(pos.x, pos.y);
|
611
|
+
});
|
612
|
+
} else if (anchor) {
|
613
|
+
Vue.nextTick(function () {
|
614
|
+
var el = document.getElementById(anchor.slice(1));
|
615
|
+
if (el) {
|
616
|
+
window.scrollTo(window.scrollX, el.offsetTop);
|
617
|
+
}
|
618
|
+
});
|
619
|
+
}
|
620
|
+
};
|
621
|
+
|
622
|
+
/**
|
623
|
+
* Normalize named route object / string paths into
|
624
|
+
* a string.
|
625
|
+
*
|
626
|
+
* @param {Object|String|Number} path
|
627
|
+
* @return {String}
|
628
|
+
*/
|
629
|
+
|
630
|
+
Router.prototype._stringifyPath = function _stringifyPath(path) {
|
631
|
+
if (path && typeof path === 'object') {
|
632
|
+
if (path.name) {
|
633
|
+
var params = path.params || {};
|
634
|
+
if (path.query) {
|
635
|
+
params.queryParams = path.query;
|
636
|
+
}
|
637
|
+
return this._recognizer.generate(path.name, params);
|
638
|
+
} else if (path.path) {
|
639
|
+
return path.path;
|
640
|
+
} else {
|
641
|
+
return '';
|
642
|
+
}
|
643
|
+
} else {
|
644
|
+
return path ? path + '' : '';
|
645
|
+
}
|
646
|
+
};
|
647
|
+
|
648
|
+
return Router;
|
649
|
+
})();
|
650
|
+
|
651
|
+
function guardComponent(path, handler) {
|
652
|
+
var comp = handler.component;
|
653
|
+
if (Vue.util.isPlainObject(comp)) {
|
654
|
+
comp = handler.component = Vue.extend(comp);
|
655
|
+
}
|
656
|
+
/* istanbul ignore if */
|
657
|
+
if (typeof comp !== 'function') {
|
658
|
+
handler.component = null;
|
659
|
+
_util.warn('invalid component for route "' + path + '".');
|
660
|
+
}
|
661
|
+
}
|
662
|
+
|
663
|
+
/* Installation */
|
664
|
+
|
665
|
+
Router.installed = false;
|
666
|
+
|
667
|
+
/**
|
668
|
+
* Installation interface.
|
669
|
+
* Install the necessary directives.
|
670
|
+
*/
|
671
|
+
|
672
|
+
Router.install = function (externalVue) {
|
673
|
+
/* istanbul ignore if */
|
674
|
+
if (Router.installed) {
|
675
|
+
_util.warn('already installed.');
|
676
|
+
return;
|
677
|
+
}
|
678
|
+
Vue = externalVue;
|
679
|
+
_override2['default'](Vue);
|
680
|
+
_directivesView2['default'](Vue);
|
681
|
+
_directivesLink2['default'](Vue);
|
682
|
+
_util2['default'].Vue = Vue;
|
683
|
+
Router.installed = true;
|
684
|
+
};
|
685
|
+
|
686
|
+
// auto install
|
687
|
+
/* istanbul ignore if */
|
688
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
689
|
+
window.Vue.use(Router);
|
690
|
+
}
|
691
|
+
|
692
|
+
exports['default'] = Router;
|
693
|
+
module.exports = exports['default'];
|
694
|
+
|
695
|
+
/***/ },
|
696
|
+
/* 1 */
|
697
|
+
/***/ function(module, exports) {
|
698
|
+
|
699
|
+
"use strict";
|
700
|
+
|
701
|
+
exports["default"] = function (instance, Constructor) {
|
702
|
+
if (!(instance instanceof Constructor)) {
|
703
|
+
throw new TypeError("Cannot call a class as a function");
|
704
|
+
}
|
705
|
+
};
|
706
|
+
|
707
|
+
exports.__esModule = true;
|
708
|
+
|
709
|
+
/***/ },
|
710
|
+
/* 2 */
|
711
|
+
/***/ function(module, exports) {
|
712
|
+
|
713
|
+
"use strict";
|
714
|
+
|
715
|
+
exports["default"] = function (obj) {
|
716
|
+
return obj && obj.__esModule ? obj : {
|
717
|
+
"default": obj
|
718
|
+
};
|
719
|
+
};
|
720
|
+
|
721
|
+
exports.__esModule = true;
|
722
|
+
|
723
|
+
/***/ },
|
724
|
+
/* 3 */
|
725
|
+
/***/ function(module, exports, __webpack_require__) {
|
726
|
+
|
727
|
+
'use strict';
|
728
|
+
|
729
|
+
var _interopRequireDefault = __webpack_require__(2)['default'];
|
730
|
+
|
731
|
+
exports.__esModule = true;
|
732
|
+
exports.warn = warn;
|
733
|
+
exports.resolvePath = resolvePath;
|
734
|
+
exports.isPromise = isPromise;
|
735
|
+
exports.getRouteConfig = getRouteConfig;
|
736
|
+
exports.resolveAsyncComponent = resolveAsyncComponent;
|
737
|
+
exports.mapParams = mapParams;
|
738
|
+
|
739
|
+
var _routeRecognizer = __webpack_require__(4);
|
740
|
+
|
741
|
+
var _routeRecognizer2 = _interopRequireDefault(_routeRecognizer);
|
742
|
+
|
743
|
+
var genQuery = _routeRecognizer2['default'].prototype.generateQueryString;
|
744
|
+
|
745
|
+
// export default for holding the Vue reference
|
746
|
+
var _exports = {};
|
747
|
+
exports['default'] = _exports;
|
748
|
+
|
749
|
+
/**
|
750
|
+
* Warn stuff.
|
751
|
+
*
|
752
|
+
* @param {String} msg
|
753
|
+
*/
|
754
|
+
|
755
|
+
function warn(msg) {
|
756
|
+
/* istanbul ignore next */
|
757
|
+
if (window.console) {
|
758
|
+
console.warn('[vue-router] ' + msg);
|
759
|
+
/* istanbul ignore if */
|
760
|
+
if (!_exports.Vue || _exports.Vue.config.debug) {
|
761
|
+
console.warn(new Error('warning stack trace:').stack);
|
762
|
+
}
|
763
|
+
}
|
764
|
+
}
|
765
|
+
|
766
|
+
/**
|
767
|
+
* Resolve a relative path.
|
768
|
+
*
|
769
|
+
* @param {String} base
|
770
|
+
* @param {String} relative
|
771
|
+
* @param {Boolean} append
|
772
|
+
* @return {String}
|
773
|
+
*/
|
774
|
+
|
775
|
+
function resolvePath(base, relative, append) {
|
776
|
+
var query = base.match(/(\?.*)$/);
|
777
|
+
if (query) {
|
778
|
+
query = query[1];
|
779
|
+
base = base.slice(0, -query.length);
|
780
|
+
}
|
781
|
+
// a query!
|
782
|
+
if (relative.charAt(0) === '?') {
|
783
|
+
return base + relative;
|
784
|
+
}
|
785
|
+
var stack = base.split('/');
|
786
|
+
// remove trailing segment if:
|
787
|
+
// - not appending
|
788
|
+
// - appending to trailing slash (last segment is empty)
|
789
|
+
if (!append || !stack[stack.length - 1]) {
|
790
|
+
stack.pop();
|
791
|
+
}
|
792
|
+
// resolve relative path
|
793
|
+
var segments = relative.replace(/^\//, '').split('/');
|
794
|
+
for (var i = 0; i < segments.length; i++) {
|
795
|
+
var segment = segments[i];
|
796
|
+
if (segment === '.') {
|
797
|
+
continue;
|
798
|
+
} else if (segment === '..') {
|
799
|
+
stack.pop();
|
800
|
+
} else {
|
801
|
+
stack.push(segment);
|
802
|
+
}
|
803
|
+
}
|
804
|
+
// ensure leading slash
|
805
|
+
if (stack[0] !== '') {
|
806
|
+
stack.unshift('');
|
807
|
+
}
|
808
|
+
return stack.join('/');
|
809
|
+
}
|
810
|
+
|
811
|
+
/**
|
812
|
+
* Forgiving check for a promise
|
813
|
+
*
|
814
|
+
* @param {Object} p
|
815
|
+
* @return {Boolean}
|
816
|
+
*/
|
817
|
+
|
818
|
+
function isPromise(p) {
|
819
|
+
return p && typeof p.then === 'function';
|
820
|
+
}
|
821
|
+
|
822
|
+
/**
|
823
|
+
* Retrive a route config field from a component instance
|
824
|
+
* OR a component contructor.
|
825
|
+
*
|
826
|
+
* @param {Function|Vue} component
|
827
|
+
* @param {String} name
|
828
|
+
* @return {*}
|
829
|
+
*/
|
830
|
+
|
831
|
+
function getRouteConfig(component, name) {
|
832
|
+
var options = component && (component.$options || component.options);
|
833
|
+
return options && options.route && options.route[name];
|
834
|
+
}
|
835
|
+
|
836
|
+
/**
|
837
|
+
* Resolve an async component factory. Have to do a dirty
|
838
|
+
* mock here because of Vue core's internal API depends on
|
839
|
+
* an ID check.
|
840
|
+
*
|
841
|
+
* @param {Object} handler
|
842
|
+
* @param {Function} cb
|
843
|
+
*/
|
844
|
+
|
845
|
+
var resolver = undefined;
|
846
|
+
|
847
|
+
function resolveAsyncComponent(handler, cb) {
|
848
|
+
if (!resolver) {
|
849
|
+
resolver = {
|
850
|
+
resolve: _exports.Vue.prototype._resolveComponent,
|
851
|
+
$options: {
|
852
|
+
components: {
|
853
|
+
_: handler.component
|
854
|
+
}
|
855
|
+
}
|
856
|
+
};
|
857
|
+
} else {
|
858
|
+
resolver.$options.components._ = handler.component;
|
859
|
+
}
|
860
|
+
resolver.resolve('_', function (Component) {
|
861
|
+
handler.component = Component;
|
862
|
+
cb(Component);
|
863
|
+
});
|
864
|
+
}
|
865
|
+
|
866
|
+
/**
|
867
|
+
* Map the dynamic segments in a path to params.
|
868
|
+
*
|
869
|
+
* @param {String} path
|
870
|
+
* @param {Object} params
|
871
|
+
* @param {Object} query
|
872
|
+
*/
|
873
|
+
|
874
|
+
function mapParams(path, params, query) {
|
875
|
+
if (params === undefined) params = {};
|
876
|
+
|
877
|
+
path = path.replace(/:([^\/]+)/g, function (_, key) {
|
878
|
+
var val = params[key];
|
879
|
+
if (!val) {
|
880
|
+
warn('param "' + key + '" not found when generating ' + 'path for "' + path + '" with params ' + JSON.stringify(params));
|
881
|
+
}
|
882
|
+
return val || '';
|
883
|
+
});
|
884
|
+
if (query) {
|
885
|
+
path += genQuery(query);
|
886
|
+
}
|
887
|
+
return path;
|
888
|
+
}
|
889
|
+
|
890
|
+
/***/ },
|
891
|
+
/* 4 */
|
892
|
+
/***/ function(module, exports, __webpack_require__) {
|
893
|
+
|
894
|
+
var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module) {(function() {
|
895
|
+
"use strict";
|
896
|
+
function $$route$recognizer$dsl$$Target(path, matcher, delegate) {
|
897
|
+
this.path = path;
|
898
|
+
this.matcher = matcher;
|
899
|
+
this.delegate = delegate;
|
900
|
+
}
|
901
|
+
|
902
|
+
$$route$recognizer$dsl$$Target.prototype = {
|
903
|
+
to: function(target, callback) {
|
904
|
+
var delegate = this.delegate;
|
905
|
+
|
906
|
+
if (delegate && delegate.willAddRoute) {
|
907
|
+
target = delegate.willAddRoute(this.matcher.target, target);
|
908
|
+
}
|
909
|
+
|
910
|
+
this.matcher.add(this.path, target);
|
911
|
+
|
912
|
+
if (callback) {
|
913
|
+
if (callback.length === 0) { throw new Error("You must have an argument in the function passed to `to`"); }
|
914
|
+
this.matcher.addChild(this.path, target, callback, this.delegate);
|
915
|
+
}
|
916
|
+
return this;
|
917
|
+
}
|
918
|
+
};
|
919
|
+
|
920
|
+
function $$route$recognizer$dsl$$Matcher(target) {
|
921
|
+
this.routes = {};
|
922
|
+
this.children = {};
|
923
|
+
this.target = target;
|
924
|
+
}
|
925
|
+
|
926
|
+
$$route$recognizer$dsl$$Matcher.prototype = {
|
927
|
+
add: function(path, handler) {
|
928
|
+
this.routes[path] = handler;
|
929
|
+
},
|
930
|
+
|
931
|
+
addChild: function(path, target, callback, delegate) {
|
932
|
+
var matcher = new $$route$recognizer$dsl$$Matcher(target);
|
933
|
+
this.children[path] = matcher;
|
934
|
+
|
935
|
+
var match = $$route$recognizer$dsl$$generateMatch(path, matcher, delegate);
|
936
|
+
|
937
|
+
if (delegate && delegate.contextEntered) {
|
938
|
+
delegate.contextEntered(target, match);
|
939
|
+
}
|
940
|
+
|
941
|
+
callback(match);
|
942
|
+
}
|
943
|
+
};
|
944
|
+
|
945
|
+
function $$route$recognizer$dsl$$generateMatch(startingPath, matcher, delegate) {
|
946
|
+
return function(path, nestedCallback) {
|
947
|
+
var fullPath = startingPath + path;
|
948
|
+
|
949
|
+
if (nestedCallback) {
|
950
|
+
nestedCallback($$route$recognizer$dsl$$generateMatch(fullPath, matcher, delegate));
|
951
|
+
} else {
|
952
|
+
return new $$route$recognizer$dsl$$Target(startingPath + path, matcher, delegate);
|
953
|
+
}
|
954
|
+
};
|
955
|
+
}
|
956
|
+
|
957
|
+
function $$route$recognizer$dsl$$addRoute(routeArray, path, handler) {
|
958
|
+
var len = 0;
|
959
|
+
for (var i=0, l=routeArray.length; i<l; i++) {
|
960
|
+
len += routeArray[i].path.length;
|
961
|
+
}
|
962
|
+
|
963
|
+
path = path.substr(len);
|
964
|
+
var route = { path: path, handler: handler };
|
965
|
+
routeArray.push(route);
|
966
|
+
}
|
967
|
+
|
968
|
+
function $$route$recognizer$dsl$$eachRoute(baseRoute, matcher, callback, binding) {
|
969
|
+
var routes = matcher.routes;
|
970
|
+
|
971
|
+
for (var path in routes) {
|
972
|
+
if (routes.hasOwnProperty(path)) {
|
973
|
+
var routeArray = baseRoute.slice();
|
974
|
+
$$route$recognizer$dsl$$addRoute(routeArray, path, routes[path]);
|
975
|
+
|
976
|
+
if (matcher.children[path]) {
|
977
|
+
$$route$recognizer$dsl$$eachRoute(routeArray, matcher.children[path], callback, binding);
|
978
|
+
} else {
|
979
|
+
callback.call(binding, routeArray);
|
980
|
+
}
|
981
|
+
}
|
982
|
+
}
|
983
|
+
}
|
984
|
+
|
985
|
+
var $$route$recognizer$dsl$$default = function(callback, addRouteCallback) {
|
986
|
+
var matcher = new $$route$recognizer$dsl$$Matcher();
|
987
|
+
|
988
|
+
callback($$route$recognizer$dsl$$generateMatch("", matcher, this.delegate));
|
989
|
+
|
990
|
+
$$route$recognizer$dsl$$eachRoute([], matcher, function(route) {
|
991
|
+
if (addRouteCallback) { addRouteCallback(this, route); }
|
992
|
+
else { this.add(route); }
|
993
|
+
}, this);
|
994
|
+
};
|
995
|
+
|
996
|
+
var $$route$recognizer$$specials = [
|
997
|
+
'/', '.', '*', '+', '?', '|',
|
998
|
+
'(', ')', '[', ']', '{', '}', '\\'
|
999
|
+
];
|
1000
|
+
|
1001
|
+
var $$route$recognizer$$escapeRegex = new RegExp('(\\' + $$route$recognizer$$specials.join('|\\') + ')', 'g');
|
1002
|
+
|
1003
|
+
function $$route$recognizer$$isArray(test) {
|
1004
|
+
return Object.prototype.toString.call(test) === "[object Array]";
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
// A Segment represents a segment in the original route description.
|
1008
|
+
// Each Segment type provides an `eachChar` and `regex` method.
|
1009
|
+
//
|
1010
|
+
// The `eachChar` method invokes the callback with one or more character
|
1011
|
+
// specifications. A character specification consumes one or more input
|
1012
|
+
// characters.
|
1013
|
+
//
|
1014
|
+
// The `regex` method returns a regex fragment for the segment. If the
|
1015
|
+
// segment is a dynamic of star segment, the regex fragment also includes
|
1016
|
+
// a capture.
|
1017
|
+
//
|
1018
|
+
// A character specification contains:
|
1019
|
+
//
|
1020
|
+
// * `validChars`: a String with a list of all valid characters, or
|
1021
|
+
// * `invalidChars`: a String with a list of all invalid characters
|
1022
|
+
// * `repeat`: true if the character specification can repeat
|
1023
|
+
|
1024
|
+
function $$route$recognizer$$StaticSegment(string) { this.string = string; }
|
1025
|
+
$$route$recognizer$$StaticSegment.prototype = {
|
1026
|
+
eachChar: function(callback) {
|
1027
|
+
var string = this.string, ch;
|
1028
|
+
|
1029
|
+
for (var i=0, l=string.length; i<l; i++) {
|
1030
|
+
ch = string.charAt(i);
|
1031
|
+
callback({ validChars: ch });
|
1032
|
+
}
|
1033
|
+
},
|
1034
|
+
|
1035
|
+
regex: function() {
|
1036
|
+
return this.string.replace($$route$recognizer$$escapeRegex, '\\$1');
|
1037
|
+
},
|
1038
|
+
|
1039
|
+
generate: function() {
|
1040
|
+
return this.string;
|
1041
|
+
}
|
1042
|
+
};
|
1043
|
+
|
1044
|
+
function $$route$recognizer$$DynamicSegment(name) { this.name = name; }
|
1045
|
+
$$route$recognizer$$DynamicSegment.prototype = {
|
1046
|
+
eachChar: function(callback) {
|
1047
|
+
callback({ invalidChars: "/", repeat: true });
|
1048
|
+
},
|
1049
|
+
|
1050
|
+
regex: function() {
|
1051
|
+
return "([^/]+)";
|
1052
|
+
},
|
1053
|
+
|
1054
|
+
generate: function(params) {
|
1055
|
+
return params[this.name];
|
1056
|
+
}
|
1057
|
+
};
|
1058
|
+
|
1059
|
+
function $$route$recognizer$$StarSegment(name) { this.name = name; }
|
1060
|
+
$$route$recognizer$$StarSegment.prototype = {
|
1061
|
+
eachChar: function(callback) {
|
1062
|
+
callback({ invalidChars: "", repeat: true });
|
1063
|
+
},
|
1064
|
+
|
1065
|
+
regex: function() {
|
1066
|
+
return "(.+)";
|
1067
|
+
},
|
1068
|
+
|
1069
|
+
generate: function(params) {
|
1070
|
+
return params[this.name];
|
1071
|
+
}
|
1072
|
+
};
|
1073
|
+
|
1074
|
+
function $$route$recognizer$$EpsilonSegment() {}
|
1075
|
+
$$route$recognizer$$EpsilonSegment.prototype = {
|
1076
|
+
eachChar: function() {},
|
1077
|
+
regex: function() { return ""; },
|
1078
|
+
generate: function() { return ""; }
|
1079
|
+
};
|
1080
|
+
|
1081
|
+
function $$route$recognizer$$parse(route, names, specificity) {
|
1082
|
+
// normalize route as not starting with a "/". Recognition will
|
1083
|
+
// also normalize.
|
1084
|
+
if (route.charAt(0) === "/") { route = route.substr(1); }
|
1085
|
+
|
1086
|
+
var segments = route.split("/"), results = [];
|
1087
|
+
|
1088
|
+
// A routes has specificity determined by the order that its different segments
|
1089
|
+
// appear in. This system mirrors how the magnitude of numbers written as strings
|
1090
|
+
// works.
|
1091
|
+
// Consider a number written as: "abc". An example would be "200". Any other number written
|
1092
|
+
// "xyz" will be smaller than "abc" so long as `a > z`. For instance, "199" is smaller
|
1093
|
+
// then "200", even though "y" and "z" (which are both 9) are larger than "0" (the value
|
1094
|
+
// of (`b` and `c`). This is because the leading symbol, "2", is larger than the other
|
1095
|
+
// leading symbol, "1".
|
1096
|
+
// The rule is that symbols to the left carry more weight than symbols to the right
|
1097
|
+
// when a number is written out as a string. In the above strings, the leading digit
|
1098
|
+
// represents how many 100's are in the number, and it carries more weight than the middle
|
1099
|
+
// number which represents how many 10's are in the number.
|
1100
|
+
// This system of number magnitude works well for route specificity, too. A route written as
|
1101
|
+
// `a/b/c` will be more specific than `x/y/z` as long as `a` is more specific than
|
1102
|
+
// `x`, irrespective of the other parts.
|
1103
|
+
// Because of this similarity, we assign each type of segment a number value written as a
|
1104
|
+
// string. We can find the specificity of compound routes by concatenating these strings
|
1105
|
+
// together, from left to right. After we have looped through all of the segments,
|
1106
|
+
// we convert the string to a number.
|
1107
|
+
specificity.val = '';
|
1108
|
+
|
1109
|
+
for (var i=0, l=segments.length; i<l; i++) {
|
1110
|
+
var segment = segments[i], match;
|
1111
|
+
|
1112
|
+
if (match = segment.match(/^:([^\/]+)$/)) {
|
1113
|
+
results.push(new $$route$recognizer$$DynamicSegment(match[1]));
|
1114
|
+
names.push(match[1]);
|
1115
|
+
specificity.val += '3';
|
1116
|
+
} else if (match = segment.match(/^\*([^\/]+)$/)) {
|
1117
|
+
results.push(new $$route$recognizer$$StarSegment(match[1]));
|
1118
|
+
specificity.val += '2';
|
1119
|
+
names.push(match[1]);
|
1120
|
+
} else if(segment === "") {
|
1121
|
+
results.push(new $$route$recognizer$$EpsilonSegment());
|
1122
|
+
specificity.val += '1';
|
1123
|
+
} else {
|
1124
|
+
results.push(new $$route$recognizer$$StaticSegment(segment));
|
1125
|
+
specificity.val += '4';
|
1126
|
+
}
|
1127
|
+
}
|
1128
|
+
|
1129
|
+
specificity.val = +specificity.val;
|
1130
|
+
|
1131
|
+
return results;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
// A State has a character specification and (`charSpec`) and a list of possible
|
1135
|
+
// subsequent states (`nextStates`).
|
1136
|
+
//
|
1137
|
+
// If a State is an accepting state, it will also have several additional
|
1138
|
+
// properties:
|
1139
|
+
//
|
1140
|
+
// * `regex`: A regular expression that is used to extract parameters from paths
|
1141
|
+
// that reached this accepting state.
|
1142
|
+
// * `handlers`: Information on how to convert the list of captures into calls
|
1143
|
+
// to registered handlers with the specified parameters
|
1144
|
+
// * `types`: How many static, dynamic or star segments in this route. Used to
|
1145
|
+
// decide which route to use if multiple registered routes match a path.
|
1146
|
+
//
|
1147
|
+
// Currently, State is implemented naively by looping over `nextStates` and
|
1148
|
+
// comparing a character specification against a character. A more efficient
|
1149
|
+
// implementation would use a hash of keys pointing at one or more next states.
|
1150
|
+
|
1151
|
+
function $$route$recognizer$$State(charSpec) {
|
1152
|
+
this.charSpec = charSpec;
|
1153
|
+
this.nextStates = [];
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
$$route$recognizer$$State.prototype = {
|
1157
|
+
get: function(charSpec) {
|
1158
|
+
var nextStates = this.nextStates;
|
1159
|
+
|
1160
|
+
for (var i=0, l=nextStates.length; i<l; i++) {
|
1161
|
+
var child = nextStates[i];
|
1162
|
+
|
1163
|
+
var isEqual = child.charSpec.validChars === charSpec.validChars;
|
1164
|
+
isEqual = isEqual && child.charSpec.invalidChars === charSpec.invalidChars;
|
1165
|
+
|
1166
|
+
if (isEqual) { return child; }
|
1167
|
+
}
|
1168
|
+
},
|
1169
|
+
|
1170
|
+
put: function(charSpec) {
|
1171
|
+
var state;
|
1172
|
+
|
1173
|
+
// If the character specification already exists in a child of the current
|
1174
|
+
// state, just return that state.
|
1175
|
+
if (state = this.get(charSpec)) { return state; }
|
1176
|
+
|
1177
|
+
// Make a new state for the character spec
|
1178
|
+
state = new $$route$recognizer$$State(charSpec);
|
1179
|
+
|
1180
|
+
// Insert the new state as a child of the current state
|
1181
|
+
this.nextStates.push(state);
|
1182
|
+
|
1183
|
+
// If this character specification repeats, insert the new state as a child
|
1184
|
+
// of itself. Note that this will not trigger an infinite loop because each
|
1185
|
+
// transition during recognition consumes a character.
|
1186
|
+
if (charSpec.repeat) {
|
1187
|
+
state.nextStates.push(state);
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
// Return the new state
|
1191
|
+
return state;
|
1192
|
+
},
|
1193
|
+
|
1194
|
+
// Find a list of child states matching the next character
|
1195
|
+
match: function(ch) {
|
1196
|
+
// DEBUG "Processing `" + ch + "`:"
|
1197
|
+
var nextStates = this.nextStates,
|
1198
|
+
child, charSpec, chars;
|
1199
|
+
|
1200
|
+
// DEBUG " " + debugState(this)
|
1201
|
+
var returned = [];
|
1202
|
+
|
1203
|
+
for (var i=0, l=nextStates.length; i<l; i++) {
|
1204
|
+
child = nextStates[i];
|
1205
|
+
|
1206
|
+
charSpec = child.charSpec;
|
1207
|
+
|
1208
|
+
if (typeof (chars = charSpec.validChars) !== 'undefined') {
|
1209
|
+
if (chars.indexOf(ch) !== -1) { returned.push(child); }
|
1210
|
+
} else if (typeof (chars = charSpec.invalidChars) !== 'undefined') {
|
1211
|
+
if (chars.indexOf(ch) === -1) { returned.push(child); }
|
1212
|
+
}
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
return returned;
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
/** IF DEBUG
|
1219
|
+
, debug: function() {
|
1220
|
+
var charSpec = this.charSpec,
|
1221
|
+
debug = "[",
|
1222
|
+
chars = charSpec.validChars || charSpec.invalidChars;
|
1223
|
+
|
1224
|
+
if (charSpec.invalidChars) { debug += "^"; }
|
1225
|
+
debug += chars;
|
1226
|
+
debug += "]";
|
1227
|
+
|
1228
|
+
if (charSpec.repeat) { debug += "+"; }
|
1229
|
+
|
1230
|
+
return debug;
|
1231
|
+
}
|
1232
|
+
END IF **/
|
1233
|
+
};
|
1234
|
+
|
1235
|
+
/** IF DEBUG
|
1236
|
+
function debug(log) {
|
1237
|
+
console.log(log);
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
function debugState(state) {
|
1241
|
+
return state.nextStates.map(function(n) {
|
1242
|
+
if (n.nextStates.length === 0) { return "( " + n.debug() + " [accepting] )"; }
|
1243
|
+
return "( " + n.debug() + " <then> " + n.nextStates.map(function(s) { return s.debug() }).join(" or ") + " )";
|
1244
|
+
}).join(", ")
|
1245
|
+
}
|
1246
|
+
END IF **/
|
1247
|
+
|
1248
|
+
// Sort the routes by specificity
|
1249
|
+
function $$route$recognizer$$sortSolutions(states) {
|
1250
|
+
return states.sort(function(a, b) {
|
1251
|
+
return b.specificity.val - a.specificity.val;
|
1252
|
+
});
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
function $$route$recognizer$$recognizeChar(states, ch) {
|
1256
|
+
var nextStates = [];
|
1257
|
+
|
1258
|
+
for (var i=0, l=states.length; i<l; i++) {
|
1259
|
+
var state = states[i];
|
1260
|
+
|
1261
|
+
nextStates = nextStates.concat(state.match(ch));
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
return nextStates;
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
var $$route$recognizer$$oCreate = Object.create || function(proto) {
|
1268
|
+
function F() {}
|
1269
|
+
F.prototype = proto;
|
1270
|
+
return new F();
|
1271
|
+
};
|
1272
|
+
|
1273
|
+
function $$route$recognizer$$RecognizeResults(queryParams) {
|
1274
|
+
this.queryParams = queryParams || {};
|
1275
|
+
}
|
1276
|
+
$$route$recognizer$$RecognizeResults.prototype = $$route$recognizer$$oCreate({
|
1277
|
+
splice: Array.prototype.splice,
|
1278
|
+
slice: Array.prototype.slice,
|
1279
|
+
push: Array.prototype.push,
|
1280
|
+
length: 0,
|
1281
|
+
queryParams: null
|
1282
|
+
});
|
1283
|
+
|
1284
|
+
function $$route$recognizer$$findHandler(state, path, queryParams) {
|
1285
|
+
var handlers = state.handlers, regex = state.regex;
|
1286
|
+
var captures = path.match(regex), currentCapture = 1;
|
1287
|
+
var result = new $$route$recognizer$$RecognizeResults(queryParams);
|
1288
|
+
|
1289
|
+
for (var i=0, l=handlers.length; i<l; i++) {
|
1290
|
+
var handler = handlers[i], names = handler.names, params = {};
|
1291
|
+
|
1292
|
+
for (var j=0, m=names.length; j<m; j++) {
|
1293
|
+
params[names[j]] = captures[currentCapture++];
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
result.push({ handler: handler.handler, params: params, isDynamic: !!names.length });
|
1297
|
+
}
|
1298
|
+
|
1299
|
+
return result;
|
1300
|
+
}
|
1301
|
+
|
1302
|
+
function $$route$recognizer$$addSegment(currentState, segment) {
|
1303
|
+
segment.eachChar(function(ch) {
|
1304
|
+
var state;
|
1305
|
+
|
1306
|
+
currentState = currentState.put(ch);
|
1307
|
+
});
|
1308
|
+
|
1309
|
+
return currentState;
|
1310
|
+
}
|
1311
|
+
|
1312
|
+
function $$route$recognizer$$decodeQueryParamPart(part) {
|
1313
|
+
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
|
1314
|
+
part = part.replace(/\+/gm, '%20');
|
1315
|
+
return decodeURIComponent(part);
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
// The main interface
|
1319
|
+
|
1320
|
+
var $$route$recognizer$$RouteRecognizer = function() {
|
1321
|
+
this.rootState = new $$route$recognizer$$State();
|
1322
|
+
this.names = {};
|
1323
|
+
};
|
1324
|
+
|
1325
|
+
|
1326
|
+
$$route$recognizer$$RouteRecognizer.prototype = {
|
1327
|
+
add: function(routes, options) {
|
1328
|
+
var currentState = this.rootState, regex = "^",
|
1329
|
+
specificity = {},
|
1330
|
+
handlers = [], allSegments = [], name;
|
1331
|
+
|
1332
|
+
var isEmpty = true;
|
1333
|
+
|
1334
|
+
for (var i=0, l=routes.length; i<l; i++) {
|
1335
|
+
var route = routes[i], names = [];
|
1336
|
+
|
1337
|
+
var segments = $$route$recognizer$$parse(route.path, names, specificity);
|
1338
|
+
|
1339
|
+
allSegments = allSegments.concat(segments);
|
1340
|
+
|
1341
|
+
for (var j=0, m=segments.length; j<m; j++) {
|
1342
|
+
var segment = segments[j];
|
1343
|
+
|
1344
|
+
if (segment instanceof $$route$recognizer$$EpsilonSegment) { continue; }
|
1345
|
+
|
1346
|
+
isEmpty = false;
|
1347
|
+
|
1348
|
+
// Add a "/" for the new segment
|
1349
|
+
currentState = currentState.put({ validChars: "/" });
|
1350
|
+
regex += "/";
|
1351
|
+
|
1352
|
+
// Add a representation of the segment to the NFA and regex
|
1353
|
+
currentState = $$route$recognizer$$addSegment(currentState, segment);
|
1354
|
+
regex += segment.regex();
|
1355
|
+
}
|
1356
|
+
|
1357
|
+
var handler = { handler: route.handler, names: names };
|
1358
|
+
handlers.push(handler);
|
1359
|
+
}
|
1360
|
+
|
1361
|
+
if (isEmpty) {
|
1362
|
+
currentState = currentState.put({ validChars: "/" });
|
1363
|
+
regex += "/";
|
1364
|
+
}
|
1365
|
+
|
1366
|
+
currentState.handlers = handlers;
|
1367
|
+
currentState.regex = new RegExp(regex + "$");
|
1368
|
+
currentState.specificity = specificity;
|
1369
|
+
|
1370
|
+
if (name = options && options.as) {
|
1371
|
+
this.names[name] = {
|
1372
|
+
segments: allSegments,
|
1373
|
+
handlers: handlers
|
1374
|
+
};
|
1375
|
+
}
|
1376
|
+
},
|
1377
|
+
|
1378
|
+
handlersFor: function(name) {
|
1379
|
+
var route = this.names[name], result = [];
|
1380
|
+
if (!route) { throw new Error("There is no route named " + name); }
|
1381
|
+
|
1382
|
+
for (var i=0, l=route.handlers.length; i<l; i++) {
|
1383
|
+
result.push(route.handlers[i]);
|
1384
|
+
}
|
1385
|
+
|
1386
|
+
return result;
|
1387
|
+
},
|
1388
|
+
|
1389
|
+
hasRoute: function(name) {
|
1390
|
+
return !!this.names[name];
|
1391
|
+
},
|
1392
|
+
|
1393
|
+
generate: function(name, params) {
|
1394
|
+
var route = this.names[name], output = "";
|
1395
|
+
if (!route) { throw new Error("There is no route named " + name); }
|
1396
|
+
|
1397
|
+
var segments = route.segments;
|
1398
|
+
|
1399
|
+
for (var i=0, l=segments.length; i<l; i++) {
|
1400
|
+
var segment = segments[i];
|
1401
|
+
|
1402
|
+
if (segment instanceof $$route$recognizer$$EpsilonSegment) { continue; }
|
1403
|
+
|
1404
|
+
output += "/";
|
1405
|
+
output += segment.generate(params);
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
if (output.charAt(0) !== '/') { output = '/' + output; }
|
1409
|
+
|
1410
|
+
if (params && params.queryParams) {
|
1411
|
+
output += this.generateQueryString(params.queryParams, route.handlers);
|
1412
|
+
}
|
1413
|
+
|
1414
|
+
return output;
|
1415
|
+
},
|
1416
|
+
|
1417
|
+
generateQueryString: function(params, handlers) {
|
1418
|
+
var pairs = [];
|
1419
|
+
var keys = [];
|
1420
|
+
for(var key in params) {
|
1421
|
+
if (params.hasOwnProperty(key)) {
|
1422
|
+
keys.push(key);
|
1423
|
+
}
|
1424
|
+
}
|
1425
|
+
keys.sort();
|
1426
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
1427
|
+
key = keys[i];
|
1428
|
+
var value = params[key];
|
1429
|
+
if (value == null) {
|
1430
|
+
continue;
|
1431
|
+
}
|
1432
|
+
var pair = encodeURIComponent(key);
|
1433
|
+
if ($$route$recognizer$$isArray(value)) {
|
1434
|
+
for (var j = 0, l = value.length; j < l; j++) {
|
1435
|
+
var arrayPair = key + '[]' + '=' + encodeURIComponent(value[j]);
|
1436
|
+
pairs.push(arrayPair);
|
1437
|
+
}
|
1438
|
+
} else {
|
1439
|
+
pair += "=" + encodeURIComponent(value);
|
1440
|
+
pairs.push(pair);
|
1441
|
+
}
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
if (pairs.length === 0) { return ''; }
|
1445
|
+
|
1446
|
+
return "?" + pairs.join("&");
|
1447
|
+
},
|
1448
|
+
|
1449
|
+
parseQueryString: function(queryString) {
|
1450
|
+
var pairs = queryString.split("&"), queryParams = {};
|
1451
|
+
for(var i=0; i < pairs.length; i++) {
|
1452
|
+
var pair = pairs[i].split('='),
|
1453
|
+
key = $$route$recognizer$$decodeQueryParamPart(pair[0]),
|
1454
|
+
keyLength = key.length,
|
1455
|
+
isArray = false,
|
1456
|
+
value;
|
1457
|
+
if (pair.length === 1) {
|
1458
|
+
value = 'true';
|
1459
|
+
} else {
|
1460
|
+
//Handle arrays
|
1461
|
+
if (keyLength > 2 && key.slice(keyLength -2) === '[]') {
|
1462
|
+
isArray = true;
|
1463
|
+
key = key.slice(0, keyLength - 2);
|
1464
|
+
if(!queryParams[key]) {
|
1465
|
+
queryParams[key] = [];
|
1466
|
+
}
|
1467
|
+
}
|
1468
|
+
value = pair[1] ? $$route$recognizer$$decodeQueryParamPart(pair[1]) : '';
|
1469
|
+
}
|
1470
|
+
if (isArray) {
|
1471
|
+
queryParams[key].push(value);
|
1472
|
+
} else {
|
1473
|
+
queryParams[key] = value;
|
1474
|
+
}
|
1475
|
+
}
|
1476
|
+
return queryParams;
|
1477
|
+
},
|
1478
|
+
|
1479
|
+
recognize: function(path) {
|
1480
|
+
var states = [ this.rootState ],
|
1481
|
+
pathLen, i, l, queryStart, queryParams = {},
|
1482
|
+
isSlashDropped = false;
|
1483
|
+
|
1484
|
+
queryStart = path.indexOf('?');
|
1485
|
+
if (queryStart !== -1) {
|
1486
|
+
var queryString = path.substr(queryStart + 1, path.length);
|
1487
|
+
path = path.substr(0, queryStart);
|
1488
|
+
queryParams = this.parseQueryString(queryString);
|
1489
|
+
}
|
1490
|
+
|
1491
|
+
path = decodeURI(path);
|
1492
|
+
|
1493
|
+
// DEBUG GROUP path
|
1494
|
+
|
1495
|
+
if (path.charAt(0) !== "/") { path = "/" + path; }
|
1496
|
+
|
1497
|
+
pathLen = path.length;
|
1498
|
+
if (pathLen > 1 && path.charAt(pathLen - 1) === "/") {
|
1499
|
+
path = path.substr(0, pathLen - 1);
|
1500
|
+
isSlashDropped = true;
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
for (i=0, l=path.length; i<l; i++) {
|
1504
|
+
states = $$route$recognizer$$recognizeChar(states, path.charAt(i));
|
1505
|
+
if (!states.length) { break; }
|
1506
|
+
}
|
1507
|
+
|
1508
|
+
// END DEBUG GROUP
|
1509
|
+
|
1510
|
+
var solutions = [];
|
1511
|
+
for (i=0, l=states.length; i<l; i++) {
|
1512
|
+
if (states[i].handlers) { solutions.push(states[i]); }
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
states = $$route$recognizer$$sortSolutions(solutions);
|
1516
|
+
|
1517
|
+
var state = solutions[0];
|
1518
|
+
|
1519
|
+
if (state && state.handlers) {
|
1520
|
+
// if a trailing slash was dropped and a star segment is the last segment
|
1521
|
+
// specified, put the trailing slash back
|
1522
|
+
if (isSlashDropped && state.regex.source.slice(-5) === "(.+)$") {
|
1523
|
+
path = path + "/";
|
1524
|
+
}
|
1525
|
+
return $$route$recognizer$$findHandler(state, path, queryParams);
|
1526
|
+
}
|
1527
|
+
}
|
1528
|
+
};
|
1529
|
+
|
1530
|
+
$$route$recognizer$$RouteRecognizer.prototype.map = $$route$recognizer$dsl$$default;
|
1531
|
+
|
1532
|
+
$$route$recognizer$$RouteRecognizer.VERSION = '0.1.9';
|
1533
|
+
|
1534
|
+
var $$route$recognizer$$default = $$route$recognizer$$RouteRecognizer;
|
1535
|
+
|
1536
|
+
/* global define:true module:true window: true */
|
1537
|
+
if ("function" === 'function' && __webpack_require__(6)['amd']) {
|
1538
|
+
!(__WEBPACK_AMD_DEFINE_RESULT__ = function() { return $$route$recognizer$$default; }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
1539
|
+
} else if (typeof module !== 'undefined' && module['exports']) {
|
1540
|
+
module['exports'] = $$route$recognizer$$default;
|
1541
|
+
} else if (typeof this !== 'undefined') {
|
1542
|
+
this['RouteRecognizer'] = $$route$recognizer$$default;
|
1543
|
+
}
|
1544
|
+
}).call(this);
|
1545
|
+
|
1546
|
+
//# sourceMappingURL=route-recognizer.js.map
|
1547
|
+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)(module)))
|
1548
|
+
|
1549
|
+
/***/ },
|
1550
|
+
/* 5 */
|
1551
|
+
/***/ function(module, exports) {
|
1552
|
+
|
1553
|
+
module.exports = function(module) {
|
1554
|
+
if(!module.webpackPolyfill) {
|
1555
|
+
module.deprecate = function() {};
|
1556
|
+
module.paths = [];
|
1557
|
+
// module.parent = undefined by default
|
1558
|
+
module.children = [];
|
1559
|
+
module.webpackPolyfill = 1;
|
1560
|
+
}
|
1561
|
+
return module;
|
1562
|
+
}
|
1563
|
+
|
1564
|
+
|
1565
|
+
/***/ },
|
1566
|
+
/* 6 */
|
1567
|
+
/***/ function(module, exports) {
|
1568
|
+
|
1569
|
+
module.exports = function() { throw new Error("define cannot be used indirect"); };
|
1570
|
+
|
1571
|
+
|
1572
|
+
/***/ },
|
1573
|
+
/* 7 */
|
1574
|
+
/***/ function(module, exports) {
|
1575
|
+
|
1576
|
+
'use strict';
|
1577
|
+
|
1578
|
+
exports.__esModule = true;
|
1579
|
+
|
1580
|
+
exports['default'] = function (Vue) {
|
1581
|
+
|
1582
|
+
var _ = Vue.util;
|
1583
|
+
|
1584
|
+
// override Vue's init and destroy process to keep track of router instances
|
1585
|
+
var init = Vue.prototype._init;
|
1586
|
+
Vue.prototype._init = function (options) {
|
1587
|
+
var root = options._parent || options.parent || this;
|
1588
|
+
var route = root.$route;
|
1589
|
+
if (route) {
|
1590
|
+
route.router._children.push(this);
|
1591
|
+
if (!this.$route) {
|
1592
|
+
/* istanbul ignore if */
|
1593
|
+
if (this._defineMeta) {
|
1594
|
+
// 0.12
|
1595
|
+
this._defineMeta('$route', route);
|
1596
|
+
} else {
|
1597
|
+
// 1.0
|
1598
|
+
_.defineReactive(this, '$route', route);
|
1599
|
+
}
|
1600
|
+
}
|
1601
|
+
}
|
1602
|
+
init.call(this, options);
|
1603
|
+
};
|
1604
|
+
|
1605
|
+
var destroy = Vue.prototype._destroy;
|
1606
|
+
Vue.prototype._destroy = function () {
|
1607
|
+
if (!this._isBeingDestroyed) {
|
1608
|
+
var route = this.$root.$route;
|
1609
|
+
if (route) {
|
1610
|
+
route.router._children.$remove(this);
|
1611
|
+
}
|
1612
|
+
destroy.apply(this, arguments);
|
1613
|
+
}
|
1614
|
+
};
|
1615
|
+
|
1616
|
+
// 1.0 only: enable route mixins
|
1617
|
+
var strats = Vue.config.optionMergeStrategies;
|
1618
|
+
var hooksToMergeRE = /^(data|activate|deactivate)$/;
|
1619
|
+
|
1620
|
+
if (strats) {
|
1621
|
+
strats.route = function (parentVal, childVal) {
|
1622
|
+
if (!childVal) return parentVal;
|
1623
|
+
if (!parentVal) return childVal;
|
1624
|
+
var ret = {};
|
1625
|
+
_.extend(ret, parentVal);
|
1626
|
+
for (var key in childVal) {
|
1627
|
+
var a = ret[key];
|
1628
|
+
var b = childVal[key];
|
1629
|
+
// for data, activate and deactivate, we need to merge them into
|
1630
|
+
// arrays similar to lifecycle hooks.
|
1631
|
+
if (a && hooksToMergeRE.test(key)) {
|
1632
|
+
ret[key] = (_.isArray(a) ? a : [a]).concat(b);
|
1633
|
+
} else {
|
1634
|
+
ret[key] = b;
|
1635
|
+
}
|
1636
|
+
}
|
1637
|
+
return ret;
|
1638
|
+
};
|
1639
|
+
}
|
1640
|
+
};
|
1641
|
+
|
1642
|
+
module.exports = exports['default'];
|
1643
|
+
|
1644
|
+
/***/ },
|
1645
|
+
/* 8 */
|
1646
|
+
/***/ function(module, exports, __webpack_require__) {
|
1647
|
+
|
1648
|
+
"use strict";
|
1649
|
+
|
1650
|
+
var _classCallCheck = __webpack_require__(1)["default"];
|
1651
|
+
|
1652
|
+
var _Object$freeze = __webpack_require__(9)["default"];
|
1653
|
+
|
1654
|
+
exports.__esModule = true;
|
1655
|
+
var internalKeysRE = /^(component|subRoutes)$/;
|
1656
|
+
|
1657
|
+
/**
|
1658
|
+
* Route Context Object
|
1659
|
+
*
|
1660
|
+
* @param {String} path
|
1661
|
+
* @param {Router} router
|
1662
|
+
*/
|
1663
|
+
|
1664
|
+
var Route = function Route(path, router) {
|
1665
|
+
var _this = this;
|
1666
|
+
|
1667
|
+
_classCallCheck(this, Route);
|
1668
|
+
|
1669
|
+
var matched = router._recognizer.recognize(path);
|
1670
|
+
if (matched) {
|
1671
|
+
// copy all custom fields from route configs
|
1672
|
+
[].forEach.call(matched, function (match) {
|
1673
|
+
for (var key in match.handler) {
|
1674
|
+
if (!internalKeysRE.test(key)) {
|
1675
|
+
_this[key] = match.handler[key];
|
1676
|
+
}
|
1677
|
+
}
|
1678
|
+
});
|
1679
|
+
// set query and params
|
1680
|
+
this.query = matched.queryParams;
|
1681
|
+
this.params = [].reduce.call(matched, function (prev, cur) {
|
1682
|
+
if (cur.params) {
|
1683
|
+
for (var key in cur.params) {
|
1684
|
+
prev[key] = cur.params[key];
|
1685
|
+
}
|
1686
|
+
}
|
1687
|
+
return prev;
|
1688
|
+
}, {});
|
1689
|
+
}
|
1690
|
+
// expose path and router
|
1691
|
+
this.path = path;
|
1692
|
+
this.router = router;
|
1693
|
+
// for internal use
|
1694
|
+
this.matched = matched || router._notFoundHandler;
|
1695
|
+
// Important: freeze self to prevent observation
|
1696
|
+
_Object$freeze(this);
|
1697
|
+
};
|
1698
|
+
|
1699
|
+
exports["default"] = Route;
|
1700
|
+
module.exports = exports["default"];
|
1701
|
+
|
1702
|
+
/***/ },
|
1703
|
+
/* 9 */
|
1704
|
+
/***/ function(module, exports, __webpack_require__) {
|
1705
|
+
|
1706
|
+
module.exports = { "default": __webpack_require__(10), __esModule: true };
|
1707
|
+
|
1708
|
+
/***/ },
|
1709
|
+
/* 10 */
|
1710
|
+
/***/ function(module, exports, __webpack_require__) {
|
1711
|
+
|
1712
|
+
__webpack_require__(11);
|
1713
|
+
module.exports = __webpack_require__(16).Object.freeze;
|
1714
|
+
|
1715
|
+
/***/ },
|
1716
|
+
/* 11 */
|
1717
|
+
/***/ function(module, exports, __webpack_require__) {
|
1718
|
+
|
1719
|
+
// 19.1.2.5 Object.freeze(O)
|
1720
|
+
var isObject = __webpack_require__(12);
|
1721
|
+
|
1722
|
+
__webpack_require__(13)('freeze', function($freeze){
|
1723
|
+
return function freeze(it){
|
1724
|
+
return $freeze && isObject(it) ? $freeze(it) : it;
|
1725
|
+
};
|
1726
|
+
});
|
1727
|
+
|
1728
|
+
/***/ },
|
1729
|
+
/* 12 */
|
1730
|
+
/***/ function(module, exports) {
|
1731
|
+
|
1732
|
+
// http://jsperf.com/core-js-isobject
|
1733
|
+
module.exports = function(it){
|
1734
|
+
return it !== null && (typeof it == 'object' || typeof it == 'function');
|
1735
|
+
};
|
1736
|
+
|
1737
|
+
/***/ },
|
1738
|
+
/* 13 */
|
1739
|
+
/***/ function(module, exports, __webpack_require__) {
|
1740
|
+
|
1741
|
+
// most Object methods by ES6 should accept primitives
|
1742
|
+
module.exports = function(KEY, exec){
|
1743
|
+
var $def = __webpack_require__(14)
|
1744
|
+
, fn = (__webpack_require__(16).Object || {})[KEY] || Object[KEY]
|
1745
|
+
, exp = {};
|
1746
|
+
exp[KEY] = exec(fn);
|
1747
|
+
$def($def.S + $def.F * __webpack_require__(17)(function(){ fn(1); }), 'Object', exp);
|
1748
|
+
};
|
1749
|
+
|
1750
|
+
/***/ },
|
1751
|
+
/* 14 */
|
1752
|
+
/***/ function(module, exports, __webpack_require__) {
|
1753
|
+
|
1754
|
+
var global = __webpack_require__(15)
|
1755
|
+
, core = __webpack_require__(16)
|
1756
|
+
, PROTOTYPE = 'prototype';
|
1757
|
+
var ctx = function(fn, that){
|
1758
|
+
return function(){
|
1759
|
+
return fn.apply(that, arguments);
|
1760
|
+
};
|
1761
|
+
};
|
1762
|
+
var $def = function(type, name, source){
|
1763
|
+
var key, own, out, exp
|
1764
|
+
, isGlobal = type & $def.G
|
1765
|
+
, isProto = type & $def.P
|
1766
|
+
, target = isGlobal ? global : type & $def.S
|
1767
|
+
? global[name] : (global[name] || {})[PROTOTYPE]
|
1768
|
+
, exports = isGlobal ? core : core[name] || (core[name] = {});
|
1769
|
+
if(isGlobal)source = name;
|
1770
|
+
for(key in source){
|
1771
|
+
// contains in native
|
1772
|
+
own = !(type & $def.F) && target && key in target;
|
1773
|
+
if(own && key in exports)continue;
|
1774
|
+
// export native or passed
|
1775
|
+
out = own ? target[key] : source[key];
|
1776
|
+
// prevent global pollution for namespaces
|
1777
|
+
if(isGlobal && typeof target[key] != 'function')exp = source[key];
|
1778
|
+
// bind timers to global for call from export context
|
1779
|
+
else if(type & $def.B && own)exp = ctx(out, global);
|
1780
|
+
// wrap global constructors for prevent change them in library
|
1781
|
+
else if(type & $def.W && target[key] == out)!function(C){
|
1782
|
+
exp = function(param){
|
1783
|
+
return this instanceof C ? new C(param) : C(param);
|
1784
|
+
};
|
1785
|
+
exp[PROTOTYPE] = C[PROTOTYPE];
|
1786
|
+
}(out);
|
1787
|
+
else exp = isProto && typeof out == 'function' ? ctx(Function.call, out) : out;
|
1788
|
+
// export
|
1789
|
+
exports[key] = exp;
|
1790
|
+
if(isProto)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out;
|
1791
|
+
}
|
1792
|
+
};
|
1793
|
+
// type bitmap
|
1794
|
+
$def.F = 1; // forced
|
1795
|
+
$def.G = 2; // global
|
1796
|
+
$def.S = 4; // static
|
1797
|
+
$def.P = 8; // proto
|
1798
|
+
$def.B = 16; // bind
|
1799
|
+
$def.W = 32; // wrap
|
1800
|
+
module.exports = $def;
|
1801
|
+
|
1802
|
+
/***/ },
|
1803
|
+
/* 15 */
|
1804
|
+
/***/ function(module, exports) {
|
1805
|
+
|
1806
|
+
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
1807
|
+
var UNDEFINED = 'undefined';
|
1808
|
+
var global = module.exports = typeof window != UNDEFINED && window.Math == Math
|
1809
|
+
? window : typeof self != UNDEFINED && self.Math == Math ? self : Function('return this')();
|
1810
|
+
if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef
|
1811
|
+
|
1812
|
+
/***/ },
|
1813
|
+
/* 16 */
|
1814
|
+
/***/ function(module, exports) {
|
1815
|
+
|
1816
|
+
var core = module.exports = {};
|
1817
|
+
if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef
|
1818
|
+
|
1819
|
+
/***/ },
|
1820
|
+
/* 17 */
|
1821
|
+
/***/ function(module, exports) {
|
1822
|
+
|
1823
|
+
module.exports = function(exec){
|
1824
|
+
try {
|
1825
|
+
return !!exec();
|
1826
|
+
} catch(e){
|
1827
|
+
return true;
|
1828
|
+
}
|
1829
|
+
};
|
1830
|
+
|
1831
|
+
/***/ },
|
1832
|
+
/* 18 */
|
1833
|
+
/***/ function(module, exports, __webpack_require__) {
|
1834
|
+
|
1835
|
+
'use strict';
|
1836
|
+
|
1837
|
+
var _classCallCheck = __webpack_require__(1)['default'];
|
1838
|
+
|
1839
|
+
exports.__esModule = true;
|
1840
|
+
|
1841
|
+
var _util = __webpack_require__(3);
|
1842
|
+
|
1843
|
+
var _pipeline = __webpack_require__(19);
|
1844
|
+
|
1845
|
+
/**
|
1846
|
+
* A RouteTransition object manages the pipeline of a
|
1847
|
+
* router-view switching process. This is also the object
|
1848
|
+
* passed into user route hooks.
|
1849
|
+
*
|
1850
|
+
* @param {Router} router
|
1851
|
+
* @param {Route} to
|
1852
|
+
* @param {Route} from
|
1853
|
+
*/
|
1854
|
+
|
1855
|
+
var RouteTransition = (function () {
|
1856
|
+
function RouteTransition(router, to, from) {
|
1857
|
+
_classCallCheck(this, RouteTransition);
|
1858
|
+
|
1859
|
+
this.router = router;
|
1860
|
+
this.to = to;
|
1861
|
+
this.from = from;
|
1862
|
+
this.next = null;
|
1863
|
+
this.aborted = false;
|
1864
|
+
this.done = false;
|
1865
|
+
|
1866
|
+
// start by determine the queues
|
1867
|
+
|
1868
|
+
// the deactivate queue is an array of router-view
|
1869
|
+
// directive instances that need to be deactivated,
|
1870
|
+
// deepest first.
|
1871
|
+
this.deactivateQueue = router._views;
|
1872
|
+
|
1873
|
+
// check the default handler of the deepest match
|
1874
|
+
var matched = to.matched ? Array.prototype.slice.call(to.matched) : [];
|
1875
|
+
|
1876
|
+
// the activate queue is an array of route handlers
|
1877
|
+
// that need to be activated
|
1878
|
+
this.activateQueue = matched.map(function (match) {
|
1879
|
+
return match.handler;
|
1880
|
+
});
|
1881
|
+
}
|
1882
|
+
|
1883
|
+
/**
|
1884
|
+
* Abort current transition and return to previous location.
|
1885
|
+
*/
|
1886
|
+
|
1887
|
+
RouteTransition.prototype.abort = function abort() {
|
1888
|
+
if (!this.aborted) {
|
1889
|
+
this.aborted = true;
|
1890
|
+
// if the root path throws an error during validation
|
1891
|
+
// on initial load, it gets caught in an infinite loop.
|
1892
|
+
var abortingOnLoad = !this.from.path && this.to.path === '/';
|
1893
|
+
if (!abortingOnLoad) {
|
1894
|
+
this.router.replace(this.from.path || '/');
|
1895
|
+
}
|
1896
|
+
}
|
1897
|
+
};
|
1898
|
+
|
1899
|
+
/**
|
1900
|
+
* Abort current transition and redirect to a new location.
|
1901
|
+
*
|
1902
|
+
* @param {String} path
|
1903
|
+
*/
|
1904
|
+
|
1905
|
+
RouteTransition.prototype.redirect = function redirect(path) {
|
1906
|
+
if (!this.aborted) {
|
1907
|
+
this.aborted = true;
|
1908
|
+
if (typeof path === 'string') {
|
1909
|
+
path = _util.mapParams(path, this.to.params, this.to.query);
|
1910
|
+
} else {
|
1911
|
+
path.params = this.to.params;
|
1912
|
+
path.query = this.to.query;
|
1913
|
+
}
|
1914
|
+
this.router.replace(path);
|
1915
|
+
}
|
1916
|
+
};
|
1917
|
+
|
1918
|
+
/**
|
1919
|
+
* A router view transition's pipeline can be described as
|
1920
|
+
* follows, assuming we are transitioning from an existing
|
1921
|
+
* <router-view> chain [Component A, Component B] to a new
|
1922
|
+
* chain [Component A, Component C]:
|
1923
|
+
*
|
1924
|
+
* A A
|
1925
|
+
* | => |
|
1926
|
+
* B C
|
1927
|
+
*
|
1928
|
+
* 1. Reusablity phase:
|
1929
|
+
* -> canReuse(A, A)
|
1930
|
+
* -> canReuse(B, C)
|
1931
|
+
* -> determine new queues:
|
1932
|
+
* - deactivation: [B]
|
1933
|
+
* - activation: [C]
|
1934
|
+
*
|
1935
|
+
* 2. Validation phase:
|
1936
|
+
* -> canDeactivate(B)
|
1937
|
+
* -> canActivate(C)
|
1938
|
+
*
|
1939
|
+
* 3. Activation phase:
|
1940
|
+
* -> deactivate(B)
|
1941
|
+
* -> activate(C)
|
1942
|
+
*
|
1943
|
+
* Each of these steps can be asynchronous, and any
|
1944
|
+
* step can potentially abort the transition.
|
1945
|
+
*
|
1946
|
+
* @param {Function} cb
|
1947
|
+
*/
|
1948
|
+
|
1949
|
+
RouteTransition.prototype.start = function start(cb) {
|
1950
|
+
var transition = this;
|
1951
|
+
var daq = this.deactivateQueue;
|
1952
|
+
var aq = this.activateQueue;
|
1953
|
+
var rdaq = daq.slice().reverse();
|
1954
|
+
var reuseQueue = undefined;
|
1955
|
+
|
1956
|
+
// 1. Reusability phase
|
1957
|
+
var i = undefined;
|
1958
|
+
for (i = 0; i < rdaq.length; i++) {
|
1959
|
+
if (!_pipeline.canReuse(rdaq[i], aq[i], transition)) {
|
1960
|
+
break;
|
1961
|
+
}
|
1962
|
+
}
|
1963
|
+
if (i > 0) {
|
1964
|
+
reuseQueue = rdaq.slice(0, i);
|
1965
|
+
daq = rdaq.slice(i).reverse();
|
1966
|
+
aq = aq.slice(i);
|
1967
|
+
}
|
1968
|
+
|
1969
|
+
// 2. Validation phase
|
1970
|
+
transition.runQueue(daq, _pipeline.canDeactivate, function () {
|
1971
|
+
transition.runQueue(aq, _pipeline.canActivate, function () {
|
1972
|
+
transition.runQueue(daq, _pipeline.deactivate, function () {
|
1973
|
+
// 3. Activation phase
|
1974
|
+
|
1975
|
+
// Update router current route
|
1976
|
+
transition.router._onTransitionValidated(transition);
|
1977
|
+
|
1978
|
+
// trigger reuse for all reused views
|
1979
|
+
reuseQueue && reuseQueue.forEach(function (view) {
|
1980
|
+
_pipeline.reuse(view, transition);
|
1981
|
+
});
|
1982
|
+
|
1983
|
+
// the root of the chain that needs to be replaced
|
1984
|
+
// is the top-most non-reusable view.
|
1985
|
+
if (daq.length) {
|
1986
|
+
var view = daq[daq.length - 1];
|
1987
|
+
var depth = reuseQueue ? reuseQueue.length : 0;
|
1988
|
+
_pipeline.activate(view, transition, depth, cb);
|
1989
|
+
} else {
|
1990
|
+
cb();
|
1991
|
+
}
|
1992
|
+
});
|
1993
|
+
});
|
1994
|
+
});
|
1995
|
+
};
|
1996
|
+
|
1997
|
+
/**
|
1998
|
+
* Asynchronously and sequentially apply a function to a
|
1999
|
+
* queue.
|
2000
|
+
*
|
2001
|
+
* @param {Array} queue
|
2002
|
+
* @param {Function} fn
|
2003
|
+
* @param {Function} cb
|
2004
|
+
*/
|
2005
|
+
|
2006
|
+
RouteTransition.prototype.runQueue = function runQueue(queue, fn, cb) {
|
2007
|
+
var transition = this;
|
2008
|
+
step(0);
|
2009
|
+
function step(index) {
|
2010
|
+
if (index >= queue.length) {
|
2011
|
+
cb();
|
2012
|
+
} else {
|
2013
|
+
fn(queue[index], transition, function () {
|
2014
|
+
step(index + 1);
|
2015
|
+
});
|
2016
|
+
}
|
2017
|
+
}
|
2018
|
+
};
|
2019
|
+
|
2020
|
+
/**
|
2021
|
+
* Call a user provided route transition hook and handle
|
2022
|
+
* the response (e.g. if the user returns a promise).
|
2023
|
+
*
|
2024
|
+
* If the user neither expects an argument nor returns a
|
2025
|
+
* promise, the hook is assumed to be synchronous.
|
2026
|
+
*
|
2027
|
+
* @param {Function} hook
|
2028
|
+
* @param {*} [context]
|
2029
|
+
* @param {Function} [cb]
|
2030
|
+
* @param {Object} [options]
|
2031
|
+
* - {Boolean} expectBoolean
|
2032
|
+
* - {Boolean} expectData
|
2033
|
+
* - {Function} cleanup
|
2034
|
+
*/
|
2035
|
+
|
2036
|
+
RouteTransition.prototype.callHook = function callHook(hook, context, cb) {
|
2037
|
+
var _ref = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
|
2038
|
+
|
2039
|
+
var _ref$expectBoolean = _ref.expectBoolean;
|
2040
|
+
var expectBoolean = _ref$expectBoolean === undefined ? false : _ref$expectBoolean;
|
2041
|
+
var _ref$expectData = _ref.expectData;
|
2042
|
+
var expectData = _ref$expectData === undefined ? false : _ref$expectData;
|
2043
|
+
var cleanup = _ref.cleanup;
|
2044
|
+
|
2045
|
+
var transition = this;
|
2046
|
+
var nextCalled = false;
|
2047
|
+
|
2048
|
+
// abort the transition
|
2049
|
+
var abort = function abort() {
|
2050
|
+
cleanup && cleanup();
|
2051
|
+
transition.abort();
|
2052
|
+
};
|
2053
|
+
|
2054
|
+
// handle errors
|
2055
|
+
var onError = function onError(err) {
|
2056
|
+
// cleanup indicates an after-activation hook,
|
2057
|
+
// so instead of aborting we just let the transition
|
2058
|
+
// finish.
|
2059
|
+
cleanup ? next() : abort();
|
2060
|
+
if (err && !transition.router._suppress) {
|
2061
|
+
_util.warn('Uncaught error during transition: ');
|
2062
|
+
throw err instanceof Error ? err : new Error(err);
|
2063
|
+
}
|
2064
|
+
};
|
2065
|
+
|
2066
|
+
// advance the transition to the next step
|
2067
|
+
var next = function next(data) {
|
2068
|
+
if (nextCalled) {
|
2069
|
+
_util.warn('transition.next() should be called only once.');
|
2070
|
+
return;
|
2071
|
+
}
|
2072
|
+
nextCalled = true;
|
2073
|
+
if (transition.aborted) {
|
2074
|
+
cleanup && cleanup();
|
2075
|
+
return;
|
2076
|
+
}
|
2077
|
+
cb && cb(data, onError);
|
2078
|
+
};
|
2079
|
+
|
2080
|
+
// expose a clone of the transition object, so that each
|
2081
|
+
// hook gets a clean copy and prevent the user from
|
2082
|
+
// messing with the internals.
|
2083
|
+
var exposed = {
|
2084
|
+
to: transition.to,
|
2085
|
+
from: transition.from,
|
2086
|
+
abort: abort,
|
2087
|
+
next: next,
|
2088
|
+
redirect: function redirect() {
|
2089
|
+
transition.redirect.apply(transition, arguments);
|
2090
|
+
}
|
2091
|
+
};
|
2092
|
+
|
2093
|
+
// actually call the hook
|
2094
|
+
var res = undefined;
|
2095
|
+
try {
|
2096
|
+
res = hook.call(context, exposed);
|
2097
|
+
} catch (err) {
|
2098
|
+
return onError(err);
|
2099
|
+
}
|
2100
|
+
|
2101
|
+
// handle boolean/promise return values
|
2102
|
+
var resIsPromise = _util.isPromise(res);
|
2103
|
+
if (expectBoolean) {
|
2104
|
+
if (typeof res === 'boolean') {
|
2105
|
+
res ? next() : abort();
|
2106
|
+
} else if (resIsPromise) {
|
2107
|
+
res.then(function (ok) {
|
2108
|
+
ok ? next() : abort();
|
2109
|
+
}, onError);
|
2110
|
+
} else if (!hook.length) {
|
2111
|
+
next(res);
|
2112
|
+
}
|
2113
|
+
} else if (resIsPromise) {
|
2114
|
+
res.then(next, onError);
|
2115
|
+
} else if (expectData && isPlainOjbect(res) || !hook.length) {
|
2116
|
+
next(res);
|
2117
|
+
}
|
2118
|
+
};
|
2119
|
+
|
2120
|
+
/**
|
2121
|
+
* Call a single hook or an array of async hooks in series.
|
2122
|
+
*
|
2123
|
+
* @param {Array} hooks
|
2124
|
+
* @param {*} context
|
2125
|
+
* @param {Function} cb
|
2126
|
+
* @param {Object} [options]
|
2127
|
+
*/
|
2128
|
+
|
2129
|
+
RouteTransition.prototype.callHooks = function callHooks(hooks, context, cb, options) {
|
2130
|
+
var _this = this;
|
2131
|
+
|
2132
|
+
if (Array.isArray(hooks)) {
|
2133
|
+
(function () {
|
2134
|
+
var res = [];
|
2135
|
+
res._needMerge = true;
|
2136
|
+
var onError = undefined;
|
2137
|
+
_this.runQueue(hooks, function (hook, _, next) {
|
2138
|
+
if (!_this.aborted) {
|
2139
|
+
_this.callHook(hook, context, function (r, onError) {
|
2140
|
+
if (r) res.push(r);
|
2141
|
+
onError = onError;
|
2142
|
+
next();
|
2143
|
+
}, options);
|
2144
|
+
}
|
2145
|
+
}, function () {
|
2146
|
+
cb(res, onError);
|
2147
|
+
});
|
2148
|
+
})();
|
2149
|
+
} else {
|
2150
|
+
this.callHook(hooks, context, cb, options);
|
2151
|
+
}
|
2152
|
+
};
|
2153
|
+
|
2154
|
+
return RouteTransition;
|
2155
|
+
})();
|
2156
|
+
|
2157
|
+
exports['default'] = RouteTransition;
|
2158
|
+
|
2159
|
+
function isPlainOjbect(val) {
|
2160
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
2161
|
+
}
|
2162
|
+
module.exports = exports['default'];
|
2163
|
+
|
2164
|
+
/***/ },
|
2165
|
+
/* 19 */
|
2166
|
+
/***/ function(module, exports, __webpack_require__) {
|
2167
|
+
|
2168
|
+
'use strict';
|
2169
|
+
|
2170
|
+
var _Object$keys = __webpack_require__(20)['default'];
|
2171
|
+
|
2172
|
+
var _Object$create = __webpack_require__(25)['default'];
|
2173
|
+
|
2174
|
+
exports.__esModule = true;
|
2175
|
+
exports.canReuse = canReuse;
|
2176
|
+
exports.canDeactivate = canDeactivate;
|
2177
|
+
exports.canActivate = canActivate;
|
2178
|
+
exports.deactivate = deactivate;
|
2179
|
+
exports.activate = activate;
|
2180
|
+
exports.reuse = reuse;
|
2181
|
+
|
2182
|
+
var _util = __webpack_require__(3);
|
2183
|
+
|
2184
|
+
/**
|
2185
|
+
* Determine the reusability of an existing router view.
|
2186
|
+
*
|
2187
|
+
* @param {Directive} view
|
2188
|
+
* @param {Object} handler
|
2189
|
+
* @param {Transition} transition
|
2190
|
+
*/
|
2191
|
+
|
2192
|
+
function canReuse(view, handler, transition) {
|
2193
|
+
var component = view.childVM;
|
2194
|
+
if (!component || !handler) {
|
2195
|
+
return false;
|
2196
|
+
}
|
2197
|
+
// important: check view.Component here because it may
|
2198
|
+
// have been changed in activate hook
|
2199
|
+
if (view.Component !== handler.component) {
|
2200
|
+
return false;
|
2201
|
+
}
|
2202
|
+
var canReuseFn = _util.getRouteConfig(component, 'canReuse');
|
2203
|
+
return typeof canReuseFn === 'boolean' ? canReuseFn : canReuseFn ? canReuseFn.call(component, {
|
2204
|
+
to: transition.to,
|
2205
|
+
from: transition.from
|
2206
|
+
}) : true; // defaults to true
|
2207
|
+
}
|
2208
|
+
|
2209
|
+
/**
|
2210
|
+
* Check if a component can deactivate.
|
2211
|
+
*
|
2212
|
+
* @param {Directive} view
|
2213
|
+
* @param {Transition} transition
|
2214
|
+
* @param {Function} next
|
2215
|
+
*/
|
2216
|
+
|
2217
|
+
function canDeactivate(view, transition, next) {
|
2218
|
+
var fromComponent = view.childVM;
|
2219
|
+
var hook = _util.getRouteConfig(fromComponent, 'canDeactivate');
|
2220
|
+
if (!hook) {
|
2221
|
+
next();
|
2222
|
+
} else {
|
2223
|
+
transition.callHook(hook, fromComponent, next, {
|
2224
|
+
expectBoolean: true
|
2225
|
+
});
|
2226
|
+
}
|
2227
|
+
}
|
2228
|
+
|
2229
|
+
/**
|
2230
|
+
* Check if a component can activate.
|
2231
|
+
*
|
2232
|
+
* @param {Object} handler
|
2233
|
+
* @param {Transition} transition
|
2234
|
+
* @param {Function} next
|
2235
|
+
*/
|
2236
|
+
|
2237
|
+
function canActivate(handler, transition, next) {
|
2238
|
+
_util.resolveAsyncComponent(handler, function (Component) {
|
2239
|
+
// have to check due to async-ness
|
2240
|
+
if (transition.aborted) {
|
2241
|
+
return;
|
2242
|
+
}
|
2243
|
+
// determine if this component can be activated
|
2244
|
+
var hook = _util.getRouteConfig(Component, 'canActivate');
|
2245
|
+
if (!hook) {
|
2246
|
+
next();
|
2247
|
+
} else {
|
2248
|
+
transition.callHook(hook, null, next, {
|
2249
|
+
expectBoolean: true
|
2250
|
+
});
|
2251
|
+
}
|
2252
|
+
});
|
2253
|
+
}
|
2254
|
+
|
2255
|
+
/**
|
2256
|
+
* Call deactivate hooks for existing router-views.
|
2257
|
+
*
|
2258
|
+
* @param {Directive} view
|
2259
|
+
* @param {Transition} transition
|
2260
|
+
* @param {Function} next
|
2261
|
+
*/
|
2262
|
+
|
2263
|
+
function deactivate(view, transition, next) {
|
2264
|
+
var component = view.childVM;
|
2265
|
+
var hook = _util.getRouteConfig(component, 'deactivate');
|
2266
|
+
if (!hook) {
|
2267
|
+
next();
|
2268
|
+
} else {
|
2269
|
+
transition.callHooks(hook, component, next);
|
2270
|
+
}
|
2271
|
+
}
|
2272
|
+
|
2273
|
+
/**
|
2274
|
+
* Activate / switch component for a router-view.
|
2275
|
+
*
|
2276
|
+
* @param {Directive} view
|
2277
|
+
* @param {Transition} transition
|
2278
|
+
* @param {Number} depth
|
2279
|
+
* @param {Function} [cb]
|
2280
|
+
*/
|
2281
|
+
|
2282
|
+
function activate(view, transition, depth, cb, reuse) {
|
2283
|
+
var handler = transition.activateQueue[depth];
|
2284
|
+
if (!handler) {
|
2285
|
+
// fix 1.0.0-alpha.3 compat
|
2286
|
+
if (view._bound) {
|
2287
|
+
view.setComponent(null);
|
2288
|
+
}
|
2289
|
+
cb && cb();
|
2290
|
+
return;
|
2291
|
+
}
|
2292
|
+
|
2293
|
+
var Component = view.Component = handler.component;
|
2294
|
+
var activateHook = _util.getRouteConfig(Component, 'activate');
|
2295
|
+
var dataHook = _util.getRouteConfig(Component, 'data');
|
2296
|
+
var waitForData = _util.getRouteConfig(Component, 'waitForData');
|
2297
|
+
|
2298
|
+
view.depth = depth;
|
2299
|
+
view.activated = false;
|
2300
|
+
|
2301
|
+
var component = undefined;
|
2302
|
+
var loading = !!(dataHook && !waitForData);
|
2303
|
+
|
2304
|
+
// "reuse" is a flag passed down when the parent view is
|
2305
|
+
// either reused via keep-alive or as a child of a kept-alive view.
|
2306
|
+
// of course we can only reuse if the current kept-alive instance
|
2307
|
+
// is of the correct type.
|
2308
|
+
reuse = reuse && view.childVM && view.childVM.constructor === Component;
|
2309
|
+
|
2310
|
+
if (reuse) {
|
2311
|
+
// just reuse
|
2312
|
+
component = view.childVM;
|
2313
|
+
component.$loadingRouteData = loading;
|
2314
|
+
} else {
|
2315
|
+
// unbuild current component. this step also destroys
|
2316
|
+
// and removes all nested child views.
|
2317
|
+
view.unbuild(true);
|
2318
|
+
// handle keep-alive.
|
2319
|
+
// if the view has keep-alive, the child vm is not actually
|
2320
|
+
// destroyed - its nested views will still be in router's
|
2321
|
+
// view list. We need to removed these child views and
|
2322
|
+
// cache them on the child vm.
|
2323
|
+
if (view.keepAlive) {
|
2324
|
+
var views = transition.router._views;
|
2325
|
+
var i = views.indexOf(view);
|
2326
|
+
if (i > 0) {
|
2327
|
+
transition.router._views = views.slice(i);
|
2328
|
+
if (view.childVM) {
|
2329
|
+
view.childVM._routerViews = views.slice(0, i);
|
2330
|
+
}
|
2331
|
+
}
|
2332
|
+
}
|
2333
|
+
|
2334
|
+
// build the new component. this will also create the
|
2335
|
+
// direct child view of the current one. it will register
|
2336
|
+
// itself as view.childView.
|
2337
|
+
component = view.build({
|
2338
|
+
_meta: {
|
2339
|
+
$loadingRouteData: loading
|
2340
|
+
}
|
2341
|
+
});
|
2342
|
+
// handle keep-alive.
|
2343
|
+
// when a kept-alive child vm is restored, we need to
|
2344
|
+
// add its cached child views into the router's view list,
|
2345
|
+
// and also properly update current view's child view.
|
2346
|
+
if (view.keepAlive) {
|
2347
|
+
component.$loadingRouteData = loading;
|
2348
|
+
var cachedViews = component._routerViews;
|
2349
|
+
if (cachedViews) {
|
2350
|
+
transition.router._views = cachedViews.concat(transition.router._views);
|
2351
|
+
view.childView = cachedViews[cachedViews.length - 1];
|
2352
|
+
component._routerViews = null;
|
2353
|
+
}
|
2354
|
+
}
|
2355
|
+
}
|
2356
|
+
|
2357
|
+
// cleanup the component in case the transition is aborted
|
2358
|
+
// before the component is ever inserted.
|
2359
|
+
var cleanup = function cleanup() {
|
2360
|
+
component.$destroy();
|
2361
|
+
};
|
2362
|
+
|
2363
|
+
// actually insert the component and trigger transition
|
2364
|
+
var insert = function insert() {
|
2365
|
+
if (reuse) {
|
2366
|
+
cb && cb();
|
2367
|
+
return;
|
2368
|
+
}
|
2369
|
+
var router = transition.router;
|
2370
|
+
if (router._rendered || router._transitionOnLoad) {
|
2371
|
+
view.transition(component);
|
2372
|
+
} else {
|
2373
|
+
// no transition on first render, manual transition
|
2374
|
+
/* istanbul ignore if */
|
2375
|
+
if (view.setCurrent) {
|
2376
|
+
// 0.12 compat
|
2377
|
+
view.setCurrent(component);
|
2378
|
+
} else {
|
2379
|
+
// 1.0
|
2380
|
+
view.childVM = component;
|
2381
|
+
}
|
2382
|
+
component.$before(view.anchor, null, false);
|
2383
|
+
}
|
2384
|
+
cb && cb();
|
2385
|
+
};
|
2386
|
+
|
2387
|
+
// called after activation hook is resolved
|
2388
|
+
var afterActivate = function afterActivate() {
|
2389
|
+
view.activated = true;
|
2390
|
+
// activate the child view
|
2391
|
+
if (view.childView) {
|
2392
|
+
activate(view.childView, transition, depth + 1, null, reuse || view.keepAlive);
|
2393
|
+
}
|
2394
|
+
if (dataHook && waitForData) {
|
2395
|
+
// wait until data loaded to insert
|
2396
|
+
loadData(component, transition, dataHook, insert, cleanup);
|
2397
|
+
} else {
|
2398
|
+
// load data and insert at the same time
|
2399
|
+
if (dataHook) {
|
2400
|
+
loadData(component, transition, dataHook);
|
2401
|
+
}
|
2402
|
+
insert();
|
2403
|
+
}
|
2404
|
+
};
|
2405
|
+
|
2406
|
+
if (activateHook) {
|
2407
|
+
transition.callHooks(activateHook, component, afterActivate, {
|
2408
|
+
cleanup: cleanup
|
2409
|
+
});
|
2410
|
+
} else {
|
2411
|
+
afterActivate();
|
2412
|
+
}
|
2413
|
+
}
|
2414
|
+
|
2415
|
+
/**
|
2416
|
+
* Reuse a view, just reload data if necessary.
|
2417
|
+
*
|
2418
|
+
* @param {Directive} view
|
2419
|
+
* @param {Transition} transition
|
2420
|
+
*/
|
2421
|
+
|
2422
|
+
function reuse(view, transition) {
|
2423
|
+
var component = view.childVM;
|
2424
|
+
var dataHook = _util.getRouteConfig(component, 'data');
|
2425
|
+
if (dataHook) {
|
2426
|
+
loadData(component, transition, dataHook);
|
2427
|
+
}
|
2428
|
+
}
|
2429
|
+
|
2430
|
+
/**
|
2431
|
+
* Asynchronously load and apply data to component.
|
2432
|
+
*
|
2433
|
+
* @param {Vue} component
|
2434
|
+
* @param {Transition} transition
|
2435
|
+
* @param {Function} hook
|
2436
|
+
* @param {Function} cb
|
2437
|
+
* @param {Function} cleanup
|
2438
|
+
*/
|
2439
|
+
|
2440
|
+
function loadData(component, transition, hook, cb, cleanup) {
|
2441
|
+
component.$loadingRouteData = true;
|
2442
|
+
transition.callHooks(hook, component, function (data, onError) {
|
2443
|
+
// merge data from multiple data hooks
|
2444
|
+
if (Array.isArray(data) && data._needMerge) {
|
2445
|
+
data = data.reduce(function (res, obj) {
|
2446
|
+
if (isPlainObject(obj)) {
|
2447
|
+
_Object$keys(obj).forEach(function (key) {
|
2448
|
+
res[key] = obj[key];
|
2449
|
+
});
|
2450
|
+
}
|
2451
|
+
return res;
|
2452
|
+
}, _Object$create(null));
|
2453
|
+
}
|
2454
|
+
// handle promise sugar syntax
|
2455
|
+
var promises = [];
|
2456
|
+
if (isPlainObject(data)) {
|
2457
|
+
_Object$keys(data).forEach(function (key) {
|
2458
|
+
var val = data[key];
|
2459
|
+
if (_util.isPromise(val)) {
|
2460
|
+
promises.push(val.then(function (resolvedVal) {
|
2461
|
+
component.$set(key, resolvedVal);
|
2462
|
+
}));
|
2463
|
+
} else {
|
2464
|
+
component.$set(key, val);
|
2465
|
+
}
|
2466
|
+
});
|
2467
|
+
}
|
2468
|
+
if (!promises.length) {
|
2469
|
+
component.$loadingRouteData = false;
|
2470
|
+
cb && cb();
|
2471
|
+
} else {
|
2472
|
+
promises[0].constructor.all(promises).then(function (_) {
|
2473
|
+
component.$loadingRouteData = false;
|
2474
|
+
cb && cb();
|
2475
|
+
}, onError);
|
2476
|
+
}
|
2477
|
+
}, {
|
2478
|
+
cleanup: cleanup,
|
2479
|
+
expectData: true
|
2480
|
+
});
|
2481
|
+
}
|
2482
|
+
|
2483
|
+
function isPlainObject(obj) {
|
2484
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
2485
|
+
}
|
2486
|
+
|
2487
|
+
/***/ },
|
2488
|
+
/* 20 */
|
2489
|
+
/***/ function(module, exports, __webpack_require__) {
|
2490
|
+
|
2491
|
+
module.exports = { "default": __webpack_require__(21), __esModule: true };
|
2492
|
+
|
2493
|
+
/***/ },
|
2494
|
+
/* 21 */
|
2495
|
+
/***/ function(module, exports, __webpack_require__) {
|
2496
|
+
|
2497
|
+
__webpack_require__(22);
|
2498
|
+
module.exports = __webpack_require__(16).Object.keys;
|
2499
|
+
|
2500
|
+
/***/ },
|
2501
|
+
/* 22 */
|
2502
|
+
/***/ function(module, exports, __webpack_require__) {
|
2503
|
+
|
2504
|
+
// 19.1.2.14 Object.keys(O)
|
2505
|
+
var toObject = __webpack_require__(23);
|
2506
|
+
|
2507
|
+
__webpack_require__(13)('keys', function($keys){
|
2508
|
+
return function keys(it){
|
2509
|
+
return $keys(toObject(it));
|
2510
|
+
};
|
2511
|
+
});
|
2512
|
+
|
2513
|
+
/***/ },
|
2514
|
+
/* 23 */
|
2515
|
+
/***/ function(module, exports, __webpack_require__) {
|
2516
|
+
|
2517
|
+
// 7.1.13 ToObject(argument)
|
2518
|
+
var defined = __webpack_require__(24);
|
2519
|
+
module.exports = function(it){
|
2520
|
+
return Object(defined(it));
|
2521
|
+
};
|
2522
|
+
|
2523
|
+
/***/ },
|
2524
|
+
/* 24 */
|
2525
|
+
/***/ function(module, exports) {
|
2526
|
+
|
2527
|
+
// 7.2.1 RequireObjectCoercible(argument)
|
2528
|
+
module.exports = function(it){
|
2529
|
+
if(it == undefined)throw TypeError("Can't call method on " + it);
|
2530
|
+
return it;
|
2531
|
+
};
|
2532
|
+
|
2533
|
+
/***/ },
|
2534
|
+
/* 25 */
|
2535
|
+
/***/ function(module, exports, __webpack_require__) {
|
2536
|
+
|
2537
|
+
module.exports = { "default": __webpack_require__(26), __esModule: true };
|
2538
|
+
|
2539
|
+
/***/ },
|
2540
|
+
/* 26 */
|
2541
|
+
/***/ function(module, exports, __webpack_require__) {
|
2542
|
+
|
2543
|
+
var $ = __webpack_require__(27);
|
2544
|
+
module.exports = function create(P, D){
|
2545
|
+
return $.create(P, D);
|
2546
|
+
};
|
2547
|
+
|
2548
|
+
/***/ },
|
2549
|
+
/* 27 */
|
2550
|
+
/***/ function(module, exports) {
|
2551
|
+
|
2552
|
+
var $Object = Object;
|
2553
|
+
module.exports = {
|
2554
|
+
create: $Object.create,
|
2555
|
+
getProto: $Object.getPrototypeOf,
|
2556
|
+
isEnum: {}.propertyIsEnumerable,
|
2557
|
+
getDesc: $Object.getOwnPropertyDescriptor,
|
2558
|
+
setDesc: $Object.defineProperty,
|
2559
|
+
setDescs: $Object.defineProperties,
|
2560
|
+
getKeys: $Object.keys,
|
2561
|
+
getNames: $Object.getOwnPropertyNames,
|
2562
|
+
getSymbols: $Object.getOwnPropertySymbols,
|
2563
|
+
each: [].forEach
|
2564
|
+
};
|
2565
|
+
|
2566
|
+
/***/ },
|
2567
|
+
/* 28 */
|
2568
|
+
/***/ function(module, exports, __webpack_require__) {
|
2569
|
+
|
2570
|
+
'use strict';
|
2571
|
+
|
2572
|
+
exports.__esModule = true;
|
2573
|
+
|
2574
|
+
var _util = __webpack_require__(3);
|
2575
|
+
|
2576
|
+
var _pipeline = __webpack_require__(19);
|
2577
|
+
|
2578
|
+
exports['default'] = function (Vue) {
|
2579
|
+
|
2580
|
+
var _ = Vue.util;
|
2581
|
+
var componentDef =
|
2582
|
+
// 0.12
|
2583
|
+
Vue.directive('_component') ||
|
2584
|
+
// 1.0
|
2585
|
+
Vue.internalDirectives.component;
|
2586
|
+
// <router-view> extends the internal component directive
|
2587
|
+
var viewDef = _.extend({}, componentDef);
|
2588
|
+
|
2589
|
+
// with some overrides
|
2590
|
+
_.extend(viewDef, {
|
2591
|
+
|
2592
|
+
_isRouterView: true,
|
2593
|
+
|
2594
|
+
bind: function bind() {
|
2595
|
+
var route = this.vm.$route;
|
2596
|
+
/* istanbul ignore if */
|
2597
|
+
if (!route) {
|
2598
|
+
_util.warn('<router-view> can only be used inside a ' + 'router-enabled app.');
|
2599
|
+
return;
|
2600
|
+
}
|
2601
|
+
// force dynamic directive so v-component doesn't
|
2602
|
+
// attempt to build right now
|
2603
|
+
this._isDynamicLiteral = true;
|
2604
|
+
// finally, init by delegating to v-component
|
2605
|
+
componentDef.bind.call(this);
|
2606
|
+
|
2607
|
+
// all we need to do here is registering this view
|
2608
|
+
// in the router. actual component switching will be
|
2609
|
+
// managed by the pipeline.
|
2610
|
+
var router = this.router = route.router;
|
2611
|
+
router._views.unshift(this);
|
2612
|
+
|
2613
|
+
// note the views are in reverse order.
|
2614
|
+
var parentView = router._views[1];
|
2615
|
+
if (parentView) {
|
2616
|
+
// register self as a child of the parent view,
|
2617
|
+
// instead of activating now. This is so that the
|
2618
|
+
// child's activate hook is called after the
|
2619
|
+
// parent's has resolved.
|
2620
|
+
parentView.childView = this;
|
2621
|
+
}
|
2622
|
+
|
2623
|
+
// handle late-rendered view
|
2624
|
+
// two possibilities:
|
2625
|
+
// 1. root view rendered after transition has been
|
2626
|
+
// validated;
|
2627
|
+
// 2. child view rendered after parent view has been
|
2628
|
+
// activated.
|
2629
|
+
var transition = route.router._currentTransition;
|
2630
|
+
if (!parentView && transition.done || parentView && parentView.activated) {
|
2631
|
+
var depth = parentView ? parentView.depth + 1 : 0;
|
2632
|
+
_pipeline.activate(this, transition, depth);
|
2633
|
+
}
|
2634
|
+
},
|
2635
|
+
|
2636
|
+
unbind: function unbind() {
|
2637
|
+
this.router._views.$remove(this);
|
2638
|
+
componentDef.unbind.call(this);
|
2639
|
+
}
|
2640
|
+
});
|
2641
|
+
|
2642
|
+
Vue.elementDirective('router-view', viewDef);
|
2643
|
+
};
|
2644
|
+
|
2645
|
+
module.exports = exports['default'];
|
2646
|
+
|
2647
|
+
/***/ },
|
2648
|
+
/* 29 */
|
2649
|
+
/***/ function(module, exports, __webpack_require__) {
|
2650
|
+
|
2651
|
+
'use strict';
|
2652
|
+
|
2653
|
+
exports.__esModule = true;
|
2654
|
+
|
2655
|
+
var _util = __webpack_require__(3);
|
2656
|
+
|
2657
|
+
var trailingSlashRE = /\/$/;
|
2658
|
+
var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
|
2659
|
+
|
2660
|
+
// install v-link, which provides navigation support for
|
2661
|
+
// HTML5 history mode
|
2662
|
+
|
2663
|
+
exports['default'] = function (Vue) {
|
2664
|
+
|
2665
|
+
var _ = Vue.util;
|
2666
|
+
|
2667
|
+
Vue.directive('link', {
|
2668
|
+
|
2669
|
+
bind: function bind() {
|
2670
|
+
var _this = this;
|
2671
|
+
|
2672
|
+
var vm = this.vm;
|
2673
|
+
/* istanbul ignore if */
|
2674
|
+
if (!vm.$route) {
|
2675
|
+
_util.warn('v-link can only be used inside a ' + 'router-enabled app.');
|
2676
|
+
return;
|
2677
|
+
}
|
2678
|
+
var router = vm.$route.router;
|
2679
|
+
this.handler = function (e) {
|
2680
|
+
// don't redirect with control keys
|
2681
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey) return;
|
2682
|
+
// don't redirect when preventDefault called
|
2683
|
+
if (e.defaultPrevented) return;
|
2684
|
+
// don't redirect on right click
|
2685
|
+
if (e.button !== 0) return;
|
2686
|
+
|
2687
|
+
var target = _this.target;
|
2688
|
+
var go = function go(target) {
|
2689
|
+
e.preventDefault();
|
2690
|
+
if (target != null) {
|
2691
|
+
router.go(target);
|
2692
|
+
}
|
2693
|
+
};
|
2694
|
+
|
2695
|
+
if (_this.el.tagName === 'A' || e.target === _this.el) {
|
2696
|
+
// v-link on <a v-link="'path'">
|
2697
|
+
go(target);
|
2698
|
+
} else {
|
2699
|
+
// v-link delegate on <div v-link>
|
2700
|
+
var el = e.target;
|
2701
|
+
while (el && el.tagName !== 'A' && el !== _this.el) {
|
2702
|
+
el = el.parentNode;
|
2703
|
+
}
|
2704
|
+
if (!el) return;
|
2705
|
+
if (el.tagName !== 'A' || !el.href) {
|
2706
|
+
// allow not anchor
|
2707
|
+
go(target);
|
2708
|
+
} else if (sameOrigin(el)) {
|
2709
|
+
go({
|
2710
|
+
path: el.pathname,
|
2711
|
+
replace: target && target.replace,
|
2712
|
+
append: target && target.append
|
2713
|
+
});
|
2714
|
+
}
|
2715
|
+
}
|
2716
|
+
};
|
2717
|
+
this.el.addEventListener('click', this.handler);
|
2718
|
+
// manage active link class
|
2719
|
+
this.unwatch = vm.$watch('$route.path', _.bind(this.updateClasses, this));
|
2720
|
+
},
|
2721
|
+
|
2722
|
+
update: function update(path) {
|
2723
|
+
var router = this.vm.$route.router;
|
2724
|
+
var append = undefined;
|
2725
|
+
this.target = path;
|
2726
|
+
if (_.isObject(path)) {
|
2727
|
+
append = path.append;
|
2728
|
+
this.exact = path.exact;
|
2729
|
+
this.prevActiveClass = this.activeClass;
|
2730
|
+
this.activeClass = path.activeClass;
|
2731
|
+
}
|
2732
|
+
path = this.path = router._stringifyPath(path);
|
2733
|
+
this.activeRE = path && !this.exact ? new RegExp('^' + path.replace(/\/$/, '').replace(regexEscapeRE, '\\$&') + '(\\/|$)') : null;
|
2734
|
+
this.updateClasses(this.vm.$route.path);
|
2735
|
+
var isAbsolute = path.charAt(0) === '/';
|
2736
|
+
// do not format non-hash relative paths
|
2737
|
+
var href = path && (router.mode === 'hash' || isAbsolute) ? router.history.formatPath(path, append) : path;
|
2738
|
+
if (this.el.tagName === 'A') {
|
2739
|
+
if (href) {
|
2740
|
+
this.el.href = href;
|
2741
|
+
} else {
|
2742
|
+
this.el.removeAttribute('href');
|
2743
|
+
}
|
2744
|
+
}
|
2745
|
+
},
|
2746
|
+
|
2747
|
+
updateClasses: function updateClasses(path) {
|
2748
|
+
var el = this.el;
|
2749
|
+
var dest = this.path;
|
2750
|
+
var router = this.vm.$route.router;
|
2751
|
+
var activeClass = this.activeClass || router._linkActiveClass;
|
2752
|
+
// clear old class
|
2753
|
+
if (this.prevActiveClass !== activeClass) {
|
2754
|
+
_.removeClass(el, this.prevActiveClass);
|
2755
|
+
}
|
2756
|
+
// add new class
|
2757
|
+
if (this.exact) {
|
2758
|
+
if (dest === path ||
|
2759
|
+
// also allow additional trailing slash
|
2760
|
+
dest.charAt(dest.length - 1) !== '/' && dest === path.replace(trailingSlashRE, '')) {
|
2761
|
+
_.addClass(el, activeClass);
|
2762
|
+
} else {
|
2763
|
+
_.removeClass(el, activeClass);
|
2764
|
+
}
|
2765
|
+
} else {
|
2766
|
+
if (this.activeRE && this.activeRE.test(path)) {
|
2767
|
+
_.addClass(el, activeClass);
|
2768
|
+
} else {
|
2769
|
+
_.removeClass(el, activeClass);
|
2770
|
+
}
|
2771
|
+
}
|
2772
|
+
},
|
2773
|
+
|
2774
|
+
unbind: function unbind() {
|
2775
|
+
this.el.removeEventListener('click', this.handler);
|
2776
|
+
this.unwatch && this.unwatch();
|
2777
|
+
}
|
2778
|
+
});
|
2779
|
+
|
2780
|
+
function sameOrigin(link) {
|
2781
|
+
return link.protocol === location.protocol && link.hostname === location.hostname && link.port === location.port;
|
2782
|
+
}
|
2783
|
+
};
|
2784
|
+
|
2785
|
+
module.exports = exports['default'];
|
2786
|
+
|
2787
|
+
/***/ },
|
2788
|
+
/* 30 */
|
2789
|
+
/***/ function(module, exports, __webpack_require__) {
|
2790
|
+
|
2791
|
+
'use strict';
|
2792
|
+
|
2793
|
+
var _classCallCheck = __webpack_require__(1)['default'];
|
2794
|
+
|
2795
|
+
exports.__esModule = true;
|
2796
|
+
|
2797
|
+
var _util = __webpack_require__(3);
|
2798
|
+
|
2799
|
+
var AbstractHistory = (function () {
|
2800
|
+
function AbstractHistory(_ref) {
|
2801
|
+
var onChange = _ref.onChange;
|
2802
|
+
|
2803
|
+
_classCallCheck(this, AbstractHistory);
|
2804
|
+
|
2805
|
+
this.onChange = onChange;
|
2806
|
+
this.currentPath = '/';
|
2807
|
+
}
|
2808
|
+
|
2809
|
+
AbstractHistory.prototype.start = function start() {
|
2810
|
+
this.onChange('/');
|
2811
|
+
};
|
2812
|
+
|
2813
|
+
AbstractHistory.prototype.stop = function stop() {
|
2814
|
+
// noop
|
2815
|
+
};
|
2816
|
+
|
2817
|
+
AbstractHistory.prototype.go = function go(path, replace, append) {
|
2818
|
+
path = this.currentPath = this.formatPath(path, append);
|
2819
|
+
this.onChange(path);
|
2820
|
+
};
|
2821
|
+
|
2822
|
+
AbstractHistory.prototype.formatPath = function formatPath(path, append) {
|
2823
|
+
return path.charAt(0) === '/' ? path : _util.resolvePath(this.currentPath, path, append);
|
2824
|
+
};
|
2825
|
+
|
2826
|
+
return AbstractHistory;
|
2827
|
+
})();
|
2828
|
+
|
2829
|
+
exports['default'] = AbstractHistory;
|
2830
|
+
module.exports = exports['default'];
|
2831
|
+
|
2832
|
+
/***/ },
|
2833
|
+
/* 31 */
|
2834
|
+
/***/ function(module, exports, __webpack_require__) {
|
2835
|
+
|
2836
|
+
'use strict';
|
2837
|
+
|
2838
|
+
var _classCallCheck = __webpack_require__(1)['default'];
|
2839
|
+
|
2840
|
+
exports.__esModule = true;
|
2841
|
+
|
2842
|
+
var _util = __webpack_require__(3);
|
2843
|
+
|
2844
|
+
var HashHistory = (function () {
|
2845
|
+
function HashHistory(_ref) {
|
2846
|
+
var hashbang = _ref.hashbang;
|
2847
|
+
var onChange = _ref.onChange;
|
2848
|
+
|
2849
|
+
_classCallCheck(this, HashHistory);
|
2850
|
+
|
2851
|
+
this.hashbang = hashbang;
|
2852
|
+
this.onChange = onChange;
|
2853
|
+
}
|
2854
|
+
|
2855
|
+
HashHistory.prototype.start = function start() {
|
2856
|
+
var self = this;
|
2857
|
+
this.listener = function () {
|
2858
|
+
var path = location.hash;
|
2859
|
+
var raw = path.replace(/^#!?/, '');
|
2860
|
+
// always
|
2861
|
+
if (raw.charAt(0) !== '/') {
|
2862
|
+
raw = '/' + raw;
|
2863
|
+
}
|
2864
|
+
var formattedPath = self.formatPath(raw);
|
2865
|
+
if (formattedPath !== path) {
|
2866
|
+
location.replace(formattedPath);
|
2867
|
+
return;
|
2868
|
+
}
|
2869
|
+
var pathToMatch = decodeURI(path.replace(/^#!?/, '') + location.search);
|
2870
|
+
self.onChange(pathToMatch);
|
2871
|
+
};
|
2872
|
+
window.addEventListener('hashchange', this.listener);
|
2873
|
+
this.listener();
|
2874
|
+
};
|
2875
|
+
|
2876
|
+
HashHistory.prototype.stop = function stop() {
|
2877
|
+
window.removeEventListener('hashchange', this.listener);
|
2878
|
+
};
|
2879
|
+
|
2880
|
+
HashHistory.prototype.go = function go(path, replace, append) {
|
2881
|
+
path = this.formatPath(path, append);
|
2882
|
+
if (replace) {
|
2883
|
+
location.replace(path);
|
2884
|
+
} else {
|
2885
|
+
location.hash = path;
|
2886
|
+
}
|
2887
|
+
};
|
2888
|
+
|
2889
|
+
HashHistory.prototype.formatPath = function formatPath(path, append) {
|
2890
|
+
var isAbsoloute = path.charAt(0) === '/';
|
2891
|
+
var prefix = '#' + (this.hashbang ? '!' : '');
|
2892
|
+
return isAbsoloute ? prefix + path : prefix + _util.resolvePath(location.hash.replace(/^#!?/, ''), path, append);
|
2893
|
+
};
|
2894
|
+
|
2895
|
+
return HashHistory;
|
2896
|
+
})();
|
2897
|
+
|
2898
|
+
exports['default'] = HashHistory;
|
2899
|
+
module.exports = exports['default'];
|
2900
|
+
|
2901
|
+
/***/ },
|
2902
|
+
/* 32 */
|
2903
|
+
/***/ function(module, exports, __webpack_require__) {
|
2904
|
+
|
2905
|
+
'use strict';
|
2906
|
+
|
2907
|
+
var _classCallCheck = __webpack_require__(1)['default'];
|
2908
|
+
|
2909
|
+
exports.__esModule = true;
|
2910
|
+
|
2911
|
+
var _util = __webpack_require__(3);
|
2912
|
+
|
2913
|
+
var hashRE = /#.*$/;
|
2914
|
+
|
2915
|
+
var HTML5History = (function () {
|
2916
|
+
function HTML5History(_ref) {
|
2917
|
+
var root = _ref.root;
|
2918
|
+
var onChange = _ref.onChange;
|
2919
|
+
|
2920
|
+
_classCallCheck(this, HTML5History);
|
2921
|
+
|
2922
|
+
if (root) {
|
2923
|
+
// make sure there's the starting slash
|
2924
|
+
if (root.charAt(0) !== '/') {
|
2925
|
+
root = '/' + root;
|
2926
|
+
}
|
2927
|
+
// remove trailing slash
|
2928
|
+
this.root = root.replace(/\/$/, '');
|
2929
|
+
this.rootRE = new RegExp('^\\' + this.root);
|
2930
|
+
} else {
|
2931
|
+
this.root = null;
|
2932
|
+
}
|
2933
|
+
this.onChange = onChange;
|
2934
|
+
// check base tag
|
2935
|
+
var baseEl = document.querySelector('base');
|
2936
|
+
this.base = baseEl && baseEl.getAttribute('href');
|
2937
|
+
}
|
2938
|
+
|
2939
|
+
HTML5History.prototype.start = function start() {
|
2940
|
+
var _this = this;
|
2941
|
+
|
2942
|
+
this.listener = function (e) {
|
2943
|
+
var url = decodeURI(location.pathname + location.search);
|
2944
|
+
if (_this.root) {
|
2945
|
+
url = url.replace(_this.rootRE, '');
|
2946
|
+
}
|
2947
|
+
_this.onChange(url, e && e.state, location.hash);
|
2948
|
+
};
|
2949
|
+
window.addEventListener('popstate', this.listener);
|
2950
|
+
this.listener();
|
2951
|
+
};
|
2952
|
+
|
2953
|
+
HTML5History.prototype.stop = function stop() {
|
2954
|
+
window.removeEventListener('popstate', this.listener);
|
2955
|
+
};
|
2956
|
+
|
2957
|
+
HTML5History.prototype.go = function go(path, replace, append) {
|
2958
|
+
var url = this.formatPath(path, append);
|
2959
|
+
if (replace) {
|
2960
|
+
history.replaceState({}, '', url);
|
2961
|
+
} else {
|
2962
|
+
// record scroll position by replacing current state
|
2963
|
+
history.replaceState({
|
2964
|
+
pos: {
|
2965
|
+
x: window.pageXOffset,
|
2966
|
+
y: window.pageYOffset
|
2967
|
+
}
|
2968
|
+
}, '');
|
2969
|
+
// then push new state
|
2970
|
+
history.pushState({}, '', url);
|
2971
|
+
}
|
2972
|
+
var hashMatch = path.match(hashRE);
|
2973
|
+
var hash = hashMatch && hashMatch[0];
|
2974
|
+
path = url
|
2975
|
+
// strip hash so it doesn't mess up params
|
2976
|
+
.replace(hashRE, '')
|
2977
|
+
// remove root before matching
|
2978
|
+
.replace(this.rootRE, '');
|
2979
|
+
this.onChange(path, null, hash);
|
2980
|
+
};
|
2981
|
+
|
2982
|
+
HTML5History.prototype.formatPath = function formatPath(path, append) {
|
2983
|
+
return path.charAt(0) === '/'
|
2984
|
+
// absolute path
|
2985
|
+
? this.root ? this.root + '/' + path.replace(/^\//, '') : path : _util.resolvePath(this.base || location.pathname, path, append);
|
2986
|
+
};
|
2987
|
+
|
2988
|
+
return HTML5History;
|
2989
|
+
})();
|
2990
|
+
|
2991
|
+
exports['default'] = HTML5History;
|
2992
|
+
module.exports = exports['default'];
|
2993
|
+
|
2994
|
+
/***/ }
|
2995
|
+
/******/ ])
|
2996
|
+
});
|
2997
|
+
;
|