1
1
/*!
2
- * vue-router v0.7.2
2
+ * vue-router v0.7.3
3
3
* (c) 2015 Evan You
4
4
* Released under the MIT License.
5
5
*/
@@ -87,23 +87,23 @@ return /******/ (function(modules) { // webpackBootstrap
87
87
88
88
var _transition2 = _interopRequireDefault ( _transition ) ;
89
89
90
- var _directivesView = __webpack_require__ ( 25 ) ;
90
+ var _directivesView = __webpack_require__ ( 28 ) ;
91
91
92
92
var _directivesView2 = _interopRequireDefault ( _directivesView ) ;
93
93
94
- var _directivesLink = __webpack_require__ ( 26 ) ;
94
+ var _directivesLink = __webpack_require__ ( 29 ) ;
95
95
96
96
var _directivesLink2 = _interopRequireDefault ( _directivesLink ) ;
97
97
98
- var _historyAbstract = __webpack_require__ ( 27 ) ;
98
+ var _historyAbstract = __webpack_require__ ( 30 ) ;
99
99
100
100
var _historyAbstract2 = _interopRequireDefault ( _historyAbstract ) ;
101
101
102
- var _historyHash = __webpack_require__ ( 28 ) ;
102
+ var _historyHash = __webpack_require__ ( 31 ) ;
103
103
104
104
var _historyHash2 = _interopRequireDefault ( _historyHash ) ;
105
105
106
- var _historyHtml5 = __webpack_require__ ( 29 ) ;
106
+ var _historyHtml5 = __webpack_require__ ( 32 ) ;
107
107
108
108
var _historyHtml52 = _interopRequireDefault ( _historyHtml5 ) ;
109
109
@@ -478,22 +478,34 @@ return /******/ (function(modules) { // webpackBootstrap
478
478
return ;
479
479
}
480
480
481
- var prevRoute = this . _currentRoute ;
482
- var prevTransition = this . _currentTransition ;
481
+ var currentRoute = this . _currentRoute ;
482
+ var currentTransition = this . _currentTransition ;
483
483
484
- // do nothing if going to the same route.
485
- // the route only changes when a transition successfully
486
- // reaches activation; we don't need to do anything
487
- // if an ongoing transition is aborted during validation
488
- // phase.
489
- if ( prevTransition && path === prevRoute . path ) {
490
- return ;
484
+ if ( currentTransition ) {
485
+ if ( currentTransition . to . path === path ) {
486
+ // do nothing if we have an active transition going to the same path
487
+ return ;
488
+ } else if ( currentRoute . path === path ) {
489
+ // We are going to the same path, but we also have an ongoing but
490
+ // not-yet-validated transition. Abort that transition and reset to
491
+ // prev transition.
492
+ currentTransition . aborted = true ;
493
+ this . _currentTransition = this . _prevTransition ;
494
+ return ;
495
+ } else {
496
+ // going to a totally different path. abort ongoing transition.
497
+ currentTransition . aborted = true ;
498
+ }
491
499
}
492
500
493
501
// construct new route and transition context
494
502
var route = new _route2 [ 'default' ] ( path , this ) ;
495
- var transition = new _transition2 [ 'default' ] ( this , route , prevRoute ) ;
496
- this . _prevTransition = prevTransition ;
503
+ var transition = new _transition2 [ 'default' ] ( this , route , currentRoute ) ;
504
+
505
+ // current transition is updated right now.
506
+ // however, current route will only be updated after the transition has
507
+ // been validated.
508
+ this . _prevTransition = currentTransition ;
497
509
this . _currentTransition = transition ;
498
510
499
511
if ( ! this . app ) {
@@ -546,12 +558,6 @@ return /******/ (function(modules) { // webpackBootstrap
546
558
*/
547
559
548
560
Router . prototype . _onTransitionValidated = function _onTransitionValidated ( transition ) {
549
- // now that this one is validated, we can abort
550
- // the previous transition.
551
- var prevTransition = this . _prevTransition ;
552
- if ( prevTransition ) {
553
- prevTransition . aborted = true ;
554
- }
555
561
// set current route
556
562
var route = this . _currentRoute = transition . to ;
557
563
// update route context for all children
@@ -661,12 +667,6 @@ return /******/ (function(modules) { // webpackBootstrap
661
667
_directivesView2 [ 'default' ] ( Vue ) ;
662
668
_directivesLink2 [ 'default' ] ( Vue ) ;
663
669
_util2 [ 'default' ] . Vue = Vue ;
664
- // 1.0 only: enable route mixins
665
- var strats = Vue . config . optionMergeStrategies ;
666
- if ( strats ) {
667
- // use the same merge strategy as methods (object hash)
668
- strats . route = strats . methods ;
669
- }
670
670
Router . installed = true ;
671
671
} ;
672
672
@@ -1568,6 +1568,7 @@ return /******/ (function(modules) { // webpackBootstrap
1568
1568
1569
1569
var _ = Vue . util ;
1570
1570
1571
+ // override Vue's init and destroy process to keep track of router instances
1571
1572
var init = Vue . prototype . _init ;
1572
1573
Vue . prototype . _init = function ( options ) {
1573
1574
var root = options . _parent || options . parent || this ;
@@ -1598,6 +1599,31 @@ return /******/ (function(modules) { // webpackBootstrap
1598
1599
destroy . apply ( this , arguments ) ;
1599
1600
}
1600
1601
} ;
1602
+
1603
+ // 1.0 only: enable route mixins
1604
+ var strats = Vue . config . optionMergeStrategies ;
1605
+ var hooksToMergeRE = / ^ ( d a t a | a c t i v a t e | d e a c t i v a t e ) $ / ;
1606
+
1607
+ if ( strats ) {
1608
+ strats . route = function ( parentVal , childVal ) {
1609
+ if ( ! childVal ) return parentVal ;
1610
+ if ( ! parentVal ) return childVal ;
1611
+ var ret = { } ;
1612
+ _ . extend ( ret , parentVal ) ;
1613
+ for ( var key in childVal ) {
1614
+ var a = ret [ key ] ;
1615
+ var b = childVal [ key ] ;
1616
+ // for data, activate and deactivate, we need to merge them into
1617
+ // arrays similar to lifecycle hooks.
1618
+ if ( a && hooksToMergeRE . test ( key ) ) {
1619
+ ret [ key ] = ( _ . isArray ( a ) ? a : [ a ] ) . concat ( b ) ;
1620
+ } else {
1621
+ ret [ key ] = b ;
1622
+ }
1623
+ }
1624
+ return ret ;
1625
+ } ;
1626
+ }
1601
1627
} ;
1602
1628
1603
1629
module . exports = exports [ 'default' ] ;
@@ -2007,9 +2033,9 @@ return /******/ (function(modules) { // webpackBootstrap
2007
2033
var nextCalled = false ;
2008
2034
2009
2035
// abort the transition
2010
- var abort = function abort ( back ) {
2036
+ var abort = function abort ( ) {
2011
2037
cleanup && cleanup ( ) ;
2012
- transition . abort ( back ) ;
2038
+ transition . abort ( ) ;
2013
2039
} ;
2014
2040
2015
2041
// handle errors
@@ -2031,10 +2057,11 @@ return /******/ (function(modules) { // webpackBootstrap
2031
2057
return ;
2032
2058
}
2033
2059
nextCalled = true ;
2034
- if ( ! cb || transition . aborted ) {
2060
+ if ( transition . aborted ) {
2061
+ cleanup && cleanup ( ) ;
2035
2062
return ;
2036
2063
}
2037
- cb ( data , onError ) ;
2064
+ cb && cb ( data , onError ) ;
2038
2065
} ;
2039
2066
2040
2067
// expose a clone of the transition object, so that each
@@ -2077,6 +2104,40 @@ return /******/ (function(modules) { // webpackBootstrap
2077
2104
}
2078
2105
} ;
2079
2106
2107
+ /**
2108
+ * Call a single hook or an array of async hooks in series.
2109
+ *
2110
+ * @param {Array } hooks
2111
+ * @param {* } context
2112
+ * @param {Function } cb
2113
+ * @param {Object } [options]
2114
+ */
2115
+
2116
+ RouteTransition . prototype . callHooks = function callHooks ( hooks , context , cb , options ) {
2117
+ var _this = this ;
2118
+
2119
+ if ( Array . isArray ( hooks ) ) {
2120
+ ( function ( ) {
2121
+ var res = [ ] ;
2122
+ res . _needMerge = true ;
2123
+ var onError = undefined ;
2124
+ _this . runQueue ( hooks , function ( hook , _ , next ) {
2125
+ if ( ! _this . aborted ) {
2126
+ _this . callHook ( hook , context , function ( r , onError ) {
2127
+ if ( r ) res . push ( r ) ;
2128
+ onError = onError ;
2129
+ next ( ) ;
2130
+ } , options ) ;
2131
+ }
2132
+ } , function ( ) {
2133
+ cb ( res , onError ) ;
2134
+ } ) ;
2135
+ } ) ( ) ;
2136
+ } else {
2137
+ this . callHook ( hooks , context , cb , options ) ;
2138
+ }
2139
+ } ;
2140
+
2080
2141
return RouteTransition ;
2081
2142
} ) ( ) ;
2082
2143
@@ -2095,6 +2156,8 @@ return /******/ (function(modules) { // webpackBootstrap
2095
2156
2096
2157
var _Object$keys = __webpack_require__ ( 20 ) [ 'default' ] ;
2097
2158
2159
+ var _Object$create = __webpack_require__ ( 25 ) [ 'default' ] ;
2160
+
2098
2161
exports . __esModule = true ;
2099
2162
exports . canReuse = canReuse ;
2100
2163
exports . canDeactivate = canDeactivate ;
@@ -2190,7 +2253,7 @@ return /******/ (function(modules) { // webpackBootstrap
2190
2253
if ( ! hook ) {
2191
2254
next ( ) ;
2192
2255
} else {
2193
- transition . callHook ( hook , component , next ) ;
2256
+ transition . callHooks ( hook , component , next ) ;
2194
2257
}
2195
2258
}
2196
2259
@@ -2328,7 +2391,7 @@ return /******/ (function(modules) { // webpackBootstrap
2328
2391
} ;
2329
2392
2330
2393
if ( activateHook ) {
2331
- transition . callHook ( activateHook , component , afterActivate , {
2394
+ transition . callHooks ( activateHook , component , afterActivate , {
2332
2395
cleanup : cleanup
2333
2396
} ) ;
2334
2397
} else {
@@ -2363,9 +2426,21 @@ return /******/ (function(modules) { // webpackBootstrap
2363
2426
2364
2427
function loadData ( component , transition , hook , cb , cleanup ) {
2365
2428
component . $loadingRouteData = true ;
2366
- transition . callHook ( hook , component , function ( data , onError ) {
2429
+ transition . callHooks ( hook , component , function ( data , onError ) {
2430
+ // merge data from multiple data hooks
2431
+ if ( Array . isArray ( data ) && data . _needMerge ) {
2432
+ data = data . reduce ( function ( res , obj ) {
2433
+ if ( isPlainObject ( obj ) ) {
2434
+ _Object$keys ( obj ) . forEach ( function ( key ) {
2435
+ res [ key ] = obj [ key ] ;
2436
+ } ) ;
2437
+ }
2438
+ return res ;
2439
+ } , _Object$create ( null ) ) ;
2440
+ }
2441
+ // handle promise sugar syntax
2367
2442
var promises = [ ] ;
2368
- if ( Object . prototype . toString . call ( data ) === '[object Object]' ) {
2443
+ if ( isPlainObject ( data ) ) {
2369
2444
_Object$keys ( data ) . forEach ( function ( key ) {
2370
2445
var val = data [ key ] ;
2371
2446
if ( _util . isPromise ( val ) ) {
@@ -2392,6 +2467,10 @@ return /******/ (function(modules) { // webpackBootstrap
2392
2467
} ) ;
2393
2468
}
2394
2469
2470
+ function isPlainObject ( obj ) {
2471
+ return Object . prototype . toString . call ( obj ) === '[object Object]' ;
2472
+ }
2473
+
2395
2474
/***/ } ,
2396
2475
/* 20 */
2397
2476
/***/ function ( module , exports , __webpack_require__ ) {
@@ -2440,6 +2519,39 @@ return /******/ (function(modules) { // webpackBootstrap
2440
2519
2441
2520
/***/ } ,
2442
2521
/* 25 */
2522
+ /***/ function ( module , exports , __webpack_require__ ) {
2523
+
2524
+ module . exports = { "default" : __webpack_require__ ( 26 ) , __esModule : true } ;
2525
+
2526
+ /***/ } ,
2527
+ /* 26 */
2528
+ /***/ function ( module , exports , __webpack_require__ ) {
2529
+
2530
+ var $ = __webpack_require__ ( 27 ) ;
2531
+ module . exports = function create ( P , D ) {
2532
+ return $ . create ( P , D ) ;
2533
+ } ;
2534
+
2535
+ /***/ } ,
2536
+ /* 27 */
2537
+ /***/ function ( module , exports ) {
2538
+
2539
+ var $Object = Object ;
2540
+ module . exports = {
2541
+ create : $Object . create ,
2542
+ getProto : $Object . getPrototypeOf ,
2543
+ isEnum : { } . propertyIsEnumerable ,
2544
+ getDesc : $Object . getOwnPropertyDescriptor ,
2545
+ setDesc : $Object . defineProperty ,
2546
+ setDescs : $Object . defineProperties ,
2547
+ getKeys : $Object . keys ,
2548
+ getNames : $Object . getOwnPropertyNames ,
2549
+ getSymbols : $Object . getOwnPropertySymbols ,
2550
+ each : [ ] . forEach
2551
+ } ;
2552
+
2553
+ /***/ } ,
2554
+ /* 28 */
2443
2555
/***/ function ( module , exports , __webpack_require__ ) {
2444
2556
2445
2557
'use strict' ;
@@ -2520,7 +2632,7 @@ return /******/ (function(modules) { // webpackBootstrap
2520
2632
module . exports = exports [ 'default' ] ;
2521
2633
2522
2634
/***/ } ,
2523
- /* 26 */
2635
+ /* 29 */
2524
2636
/***/ function ( module , exports , __webpack_require__ ) {
2525
2637
2526
2638
'use strict' ;
@@ -2654,7 +2766,7 @@ return /******/ (function(modules) { // webpackBootstrap
2654
2766
module . exports = exports [ 'default' ] ;
2655
2767
2656
2768
/***/ } ,
2657
- /* 27 */
2769
+ /* 30 */
2658
2770
/***/ function ( module , exports , __webpack_require__ ) {
2659
2771
2660
2772
'use strict' ;
@@ -2699,7 +2811,7 @@ return /******/ (function(modules) { // webpackBootstrap
2699
2811
module . exports = exports [ 'default' ] ;
2700
2812
2701
2813
/***/ } ,
2702
- /* 28 */
2814
+ /* 31 */
2703
2815
/***/ function ( module , exports , __webpack_require__ ) {
2704
2816
2705
2817
'use strict' ;
@@ -2768,7 +2880,7 @@ return /******/ (function(modules) { // webpackBootstrap
2768
2880
module . exports = exports [ 'default' ] ;
2769
2881
2770
2882
/***/ } ,
2771
- /* 29 */
2883
+ /* 32 */
2772
2884
/***/ function ( module , exports , __webpack_require__ ) {
2773
2885
2774
2886
'use strict' ;
0 commit comments