1
1
/*!
2
- * vue-router v0.7.1
2
+ * vue-router v0.7.2
3
3
* (c) 2015 Evan You
4
4
* Released under the MIT License.
5
5
*/
@@ -71,9 +71,9 @@ return /******/ (function(modules) { // webpackBootstrap
71
71
72
72
var _util2 = _interopRequireDefault ( _util ) ;
73
73
74
- var _mixin = __webpack_require__ ( 7 ) ;
74
+ var _override = __webpack_require__ ( 7 ) ;
75
75
76
- var _mixin2 = _interopRequireDefault ( _mixin ) ;
76
+ var _override2 = _interopRequireDefault ( _override ) ;
77
77
78
78
var _routeRecognizer = __webpack_require__ ( 4 ) ;
79
79
@@ -517,7 +517,9 @@ return /******/ (function(modules) { // webpackBootstrap
517
517
if ( beforeHooks . length ) {
518
518
transition . runQueue ( beforeHooks , function ( hook , _ , next ) {
519
519
if ( transition === _this2 . _currentTransition ) {
520
- transition . callHook ( hook , null , next , true ) ;
520
+ transition . callHook ( hook , null , next , {
521
+ expectBoolean : true
522
+ } ) ;
521
523
}
522
524
} , startTransition ) ;
523
525
} else {
@@ -655,7 +657,7 @@ return /******/ (function(modules) { // webpackBootstrap
655
657
return ;
656
658
}
657
659
Vue = externalVue ;
658
- _mixin2 [ 'default' ] ( Vue ) ;
660
+ _override2 [ 'default' ] ( Vue ) ;
659
661
_directivesView2 [ 'default' ] ( Vue ) ;
660
662
_directivesLink2 [ 'default' ] ( Vue ) ;
661
663
_util2 [ 'default' ] . Vue = Vue ;
@@ -1565,53 +1567,37 @@ return /******/ (function(modules) { // webpackBootstrap
1565
1567
exports [ 'default' ] = function ( Vue ) {
1566
1568
1567
1569
var _ = Vue . util ;
1568
- var mixin = {
1569
- init : function init ( ) {
1570
- var route = this . $root . $route ;
1571
- if ( route ) {
1572
- route . router . _children . push ( this ) ;
1573
- if ( ! this . $route ) {
1570
+
1571
+ var init = Vue . prototype . _init ;
1572
+ Vue . prototype . _init = function ( options ) {
1573
+ var root = options . _parent || options . parent || this ;
1574
+ var route = root . $route ;
1575
+ if ( route ) {
1576
+ route . router . _children . push ( this ) ;
1577
+ if ( ! this . $route ) {
1578
+ /* istanbul ignore if */
1579
+ if ( this . _defineMeta ) {
1580
+ // 0.12
1581
+ this . _defineMeta ( '$route' , route ) ;
1582
+ } else {
1583
+ // 1.0
1574
1584
_ . defineReactive ( this , '$route' , route ) ;
1575
1585
}
1576
1586
}
1577
- } ,
1578
- beforeDestroy : function beforeDestroy ( ) {
1587
+ }
1588
+ init . call ( this , options ) ;
1589
+ } ;
1590
+
1591
+ var destroy = Vue . prototype . _destroy ;
1592
+ Vue . prototype . _destroy = function ( ) {
1593
+ if ( ! this . _isBeingDestroyed ) {
1579
1594
var route = this . $root . $route ;
1580
1595
if ( route ) {
1581
1596
route . router . _children . $remove ( this ) ;
1582
1597
}
1598
+ destroy . apply ( this , arguments ) ;
1583
1599
}
1584
1600
} ;
1585
-
1586
- // pre 1.0.0-rc compat
1587
- if ( ! Vue . config . optionMergeStrategies || ! Vue . config . optionMergeStrategies . init ) {
1588
- ( function ( ) {
1589
- delete mixin . init ;
1590
- var init = Vue . prototype . _init ;
1591
- Vue . prototype . _init = function ( options ) {
1592
- var root = options . _parent || options . parent || this ;
1593
- var route = root . $route ;
1594
- if ( route ) {
1595
- route . router . _children . push ( this ) ;
1596
- if ( ! this . $route ) {
1597
- if ( this . _defineMeta ) {
1598
- this . _defineMeta ( '$route' , route ) ;
1599
- } else {
1600
- _ . defineReactive ( this , '$route' , route ) ;
1601
- }
1602
- }
1603
- }
1604
- init . call ( this , options ) ;
1605
- } ;
1606
- } ) ( ) ;
1607
- }
1608
-
1609
- if ( Vue . mixin ) {
1610
- Vue . mixin ( mixin ) ;
1611
- } else {
1612
- // 0.12 compat
1613
- Vue . options = _ . mergeOptions ( Vue . options , mixin ) ;
1614
- }
1615
1601
} ;
1616
1602
1617
1603
module . exports = exports [ 'default' ] ;
@@ -1996,6 +1982,9 @@ return /******/ (function(modules) { // webpackBootstrap
1996
1982
* Call a user provided route transition hook and handle
1997
1983
* the response (e.g. if the user returns a promise).
1998
1984
*
1985
+ * If the user neither expects an argument nor returns a
1986
+ * promise, the hook is assumed to be synchronous.
1987
+ *
1999
1988
* @param {Function } hook
2000
1989
* @param {* } [context]
2001
1990
* @param {Function } [cb]
@@ -2078,10 +2067,12 @@ return /******/ (function(modules) { // webpackBootstrap
2078
2067
res . then ( function ( ok ) {
2079
2068
ok ? next ( ) : abort ( ) ;
2080
2069
} , onError ) ;
2070
+ } else if ( ! hook . length ) {
2071
+ next ( res ) ;
2081
2072
}
2082
2073
} else if ( resIsPromise ) {
2083
2074
res . then ( next , onError ) ;
2084
- } else if ( expectData && isPlainOjbect ( res ) ) {
2075
+ } else if ( expectData && isPlainOjbect ( res ) || ! hook . length ) {
2085
2076
next ( res ) ;
2086
2077
}
2087
2078
} ;
@@ -2212,7 +2203,7 @@ return /******/ (function(modules) { // webpackBootstrap
2212
2203
* @param {Function } [cb]
2213
2204
*/
2214
2205
2215
- function activate ( view , transition , depth , cb ) {
2206
+ function activate ( view , transition , depth , cb , reuse ) {
2216
2207
var handler = transition . activateQueue [ depth ] ;
2217
2208
if ( ! handler ) {
2218
2209
// fix 1.0.0-alpha.3 compat
@@ -2231,17 +2222,61 @@ return /******/ (function(modules) { // webpackBootstrap
2231
2222
view . depth = depth ;
2232
2223
view . activated = false ;
2233
2224
2234
- // unbuild current component. this step also destroys
2235
- // and removes all nested child views.
2236
- view . unbuild ( true ) ;
2237
- // build the new component. this will also create the
2238
- // direct child view of the current one. it will register
2239
- // itself as view.childView.
2240
- var component = view . build ( {
2241
- _meta : {
2242
- $loadingRouteData : ! ! ( dataHook && ! waitForData )
2225
+ var component = undefined ;
2226
+ var loading = ! ! ( dataHook && ! waitForData ) ;
2227
+
2228
+ // "reuse" is a flag passed down when the parent view is
2229
+ // either reused via keep-alive or as a child of a kept-alive view.
2230
+ // of course we can only reuse if the current kept-alive instance
2231
+ // is of the correct type.
2232
+ reuse = reuse && view . childVM && view . childVM . constructor === Component ;
2233
+
2234
+ if ( reuse ) {
2235
+ // just reuse
2236
+ component = view . childVM ;
2237
+ component . $loadingRouteData = loading ;
2238
+ } else {
2239
+ // unbuild current component. this step also destroys
2240
+ // and removes all nested child views.
2241
+ view . unbuild ( true ) ;
2242
+ // handle keep-alive.
2243
+ // if the view has keep-alive, the child vm is not actually
2244
+ // destroyed - its nested views will still be in router's
2245
+ // view list. We need to removed these child views and
2246
+ // cache them on the child vm.
2247
+ if ( view . keepAlive ) {
2248
+ var views = transition . router . _views ;
2249
+ var i = views . indexOf ( view ) ;
2250
+ if ( i > 0 ) {
2251
+ transition . router . _views = views . slice ( i ) ;
2252
+ if ( view . childVM ) {
2253
+ view . childVM . _routerViews = views . slice ( 0 , i ) ;
2254
+ }
2255
+ }
2256
+ }
2257
+
2258
+ // build the new component. this will also create the
2259
+ // direct child view of the current one. it will register
2260
+ // itself as view.childView.
2261
+ component = view . build ( {
2262
+ _meta : {
2263
+ $loadingRouteData : loading
2264
+ }
2265
+ } ) ;
2266
+ // handle keep-alive.
2267
+ // when a kept-alive child vm is restored, we need to
2268
+ // add its cached child views into the router's view list,
2269
+ // and also properly update current view's child view.
2270
+ if ( view . keepAlive ) {
2271
+ component . $loadingRouteData = loading ;
2272
+ var cachedViews = component . _routerViews ;
2273
+ if ( cachedViews ) {
2274
+ transition . router . _views = cachedViews . concat ( transition . router . _views ) ;
2275
+ view . childView = cachedViews [ cachedViews . length - 1 ] ;
2276
+ component . _routerViews = null ;
2277
+ }
2243
2278
}
2244
- } ) ;
2279
+ }
2245
2280
2246
2281
// cleanup the component in case the transition is aborted
2247
2282
// before the component is ever inserted.
@@ -2251,11 +2286,16 @@ return /******/ (function(modules) { // webpackBootstrap
2251
2286
2252
2287
// actually insert the component and trigger transition
2253
2288
var insert = function insert ( ) {
2289
+ if ( reuse ) {
2290
+ cb && cb ( ) ;
2291
+ return ;
2292
+ }
2254
2293
var router = transition . router ;
2255
2294
if ( router . _rendered || router . _transitionOnLoad ) {
2256
2295
view . transition ( component ) ;
2257
2296
} else {
2258
2297
// no transition on first render, manual transition
2298
+ /* istanbul ignore if */
2259
2299
if ( view . setCurrent ) {
2260
2300
// 0.12 compat
2261
2301
view . setCurrent ( component ) ;
@@ -2273,7 +2313,7 @@ return /******/ (function(modules) { // webpackBootstrap
2273
2313
view . activated = true ;
2274
2314
// activate the child view
2275
2315
if ( view . childView ) {
2276
- activate ( view . childView , transition , depth + 1 ) ;
2316
+ activate ( view . childView , transition , depth + 1 , null , reuse || view . keepAlive ) ;
2277
2317
}
2278
2318
if ( dataHook && waitForData ) {
2279
2319
// wait until data loaded to insert
@@ -2325,24 +2365,27 @@ return /******/ (function(modules) { // webpackBootstrap
2325
2365
component . $loadingRouteData = true ;
2326
2366
transition . callHook ( hook , component , function ( data , onError ) {
2327
2367
var promises = [ ] ;
2328
- _Object$keys ( data ) . forEach ( function ( key ) {
2329
- var val = data [ key ] ;
2330
- if ( _util . isPromise ( val ) ) {
2331
- promises . push ( val . then ( function ( resolvedVal ) {
2332
- component . $set ( key , resolvedVal ) ;
2333
- } ) ) ;
2334
- } else {
2335
- component . $set ( key , val ) ;
2336
- }
2337
- } ) ;
2368
+ if ( Object . prototype . toString . call ( data ) === '[object Object]' ) {
2369
+ _Object$keys ( data ) . forEach ( function ( key ) {
2370
+ var val = data [ key ] ;
2371
+ if ( _util . isPromise ( val ) ) {
2372
+ promises . push ( val . then ( function ( resolvedVal ) {
2373
+ component . $set ( key , resolvedVal ) ;
2374
+ } ) ) ;
2375
+ } else {
2376
+ component . $set ( key , val ) ;
2377
+ }
2378
+ } ) ;
2379
+ }
2338
2380
if ( ! promises . length ) {
2339
2381
component . $loadingRouteData = false ;
2382
+ cb && cb ( ) ;
2340
2383
} else {
2341
2384
promises [ 0 ] . constructor . all ( promises ) . then ( function ( _ ) {
2342
2385
component . $loadingRouteData = false ;
2386
+ cb && cb ( ) ;
2343
2387
} , onError ) ;
2344
2388
}
2345
- cb && cb ( data ) ;
2346
2389
} , {
2347
2390
cleanup : cleanup ,
2348
2391
expectData : true
@@ -2436,13 +2479,6 @@ return /******/ (function(modules) { // webpackBootstrap
2436
2479
// finally, init by delegating to v-component
2437
2480
componentDef . bind . call ( this ) ;
2438
2481
2439
- // does not support keep-alive.
2440
- /* istanbul ignore if */
2441
- if ( this . keepAlive ) {
2442
- this . keepAlive = false ;
2443
- _util . warn ( '<router-view> does not support keep-alive.' ) ;
2444
- }
2445
-
2446
2482
// all we need to do here is registering this view
2447
2483
// in the router. actual component switching will be
2448
2484
// managed by the pipeline.
@@ -2493,6 +2529,7 @@ return /******/ (function(modules) { // webpackBootstrap
2493
2529
2494
2530
var _util = __webpack_require__ ( 3 ) ;
2495
2531
2532
+ var trailingSlashRE = / \/ $ / ;
2496
2533
var regexEscapeRE = / [ - . * + ? ^ $ { } ( ) | [ \] \/ \\ ] / g;
2497
2534
2498
2535
// install v-link, which provides navigation support for
@@ -2587,7 +2624,9 @@ return /******/ (function(modules) { // webpackBootstrap
2587
2624
}
2588
2625
// add new class
2589
2626
if ( this . exact ) {
2590
- if ( path === dest ) {
2627
+ if ( dest === path ||
2628
+ // also allow additional trailing slash
2629
+ dest . charAt ( dest . length - 1 ) !== '/' && dest === path . replace ( trailingSlashRE , '' ) ) {
2591
2630
_ . addClass ( el , activeClass ) ;
2592
2631
} else {
2593
2632
_ . removeClass ( el , activeClass ) ;
0 commit comments