11/**
2- * vue-router v2.0.0
2+ * vue-router v2.0.1
33 * (c) 2016 Evan You
44 * @license MIT
55 */
@@ -47,13 +47,20 @@ var View = {
4747 return h ( )
4848 }
4949
50+ var name = props . name
5051 var component = inactive
51- ? cache [ props . name ]
52- : ( cache [ props . name ] = matched . components [ props . name ] )
52+ ? cache [ name ]
53+ : ( cache [ name ] = matched . components [ name ] )
5354
5455 if ( ! inactive ) {
55- ( data . hook || ( data . hook = { } ) ) . init = function ( vnode ) {
56- matched . instances [ props . name ] = vnode . child
56+ var hooks = data . hook || ( data . hook = { } )
57+ hooks . init = function ( vnode ) {
58+ matched . instances [ name ] = vnode . child
59+ }
60+ hooks . destroy = function ( vnode ) {
61+ if ( matched . instances [ name ] === vnode . child ) {
62+ matched . instances [ name ] = undefined
63+ }
5764 }
5865 }
5966
@@ -404,6 +411,15 @@ var Link = {
404411
405412 var on = {
406413 click : function ( e ) {
414+ // don't redirect with control keys
415+ /* istanbul ignore if */
416+ if ( e . metaKey || e . ctrlKey || e . shiftKey ) { return }
417+ // don't redirect when preventDefault called
418+ /* istanbul ignore if */
419+ if ( e . defaultPrevented ) { return }
420+ // don't redirect on right click
421+ /* istanbul ignore if */
422+ if ( e . button !== 0 ) { return }
407423 e . preventDefault ( )
408424 if ( this$1 . replace ) {
409425 router . replace ( to )
@@ -428,6 +444,9 @@ var Link = {
428444 aData . on = on
429445 var aAttrs = aData . attrs || ( aData . attrs = { } )
430446 aAttrs . href = href
447+ } else {
448+ // doesn't have <a> child, apply listener to self
449+ data . on = on
431450 }
432451 }
433452
@@ -1271,9 +1290,12 @@ History.prototype.confirmTransition = function confirmTransition (route, cb) {
12711290
12721291 runQueue ( queue , iterator , function ( ) {
12731292 var postEnterCbs = [ ]
1293+ var enterGuards = extractEnterGuards ( activated , postEnterCbs , function ( ) {
1294+ return this$1 . current === route
1295+ } )
12741296 // wait until async components are resolved before
12751297 // extracting in-component enter guards
1276- runQueue ( extractEnterGuards ( activated , postEnterCbs ) , iterator , function ( ) {
1298+ runQueue ( enterGuards , iterator , function ( ) {
12771299 if ( this$1 . pending === route ) {
12781300 this$1 . pending = null
12791301 cb ( route )
@@ -1340,7 +1362,11 @@ function extractLeaveGuards (matched) {
13401362 } ) . reverse ( )
13411363}
13421364
1343- function extractEnterGuards ( matched , cbs ) {
1365+ function extractEnterGuards (
1366+ matched ,
1367+ cbs ,
1368+ isValid
1369+ ) {
13441370 return flatMapComponents ( matched , function ( def , _ , match , key ) {
13451371 var guard = def && def . beforeRouteEnter
13461372 if ( guard ) {
@@ -1349,7 +1375,12 @@ function extractEnterGuards (matched, cbs) {
13491375 next ( cb )
13501376 if ( typeof cb === 'function' ) {
13511377 cbs . push ( function ( ) {
1352- cb ( match . instances [ key ] )
1378+ // #750
1379+ // if a router-view is wrapped with an out-in transition,
1380+ // the instance may not have been registered at this time.
1381+ // we will need to poll for registration until current route
1382+ // is no longer valid.
1383+ poll ( cb , match . instances , key , isValid )
13531384 } )
13541385 }
13551386 } )
@@ -1358,6 +1389,16 @@ function extractEnterGuards (matched, cbs) {
13581389 } )
13591390}
13601391
1392+ function poll ( cb , instances , key , isValid ) {
1393+ if ( instances [ key ] ) {
1394+ cb ( instances [ key ] )
1395+ } else if ( isValid ( ) ) {
1396+ setTimeout ( function ( ) {
1397+ poll ( cb , instances , key , isValid )
1398+ } , 16 )
1399+ }
1400+ }
1401+
13611402function resolveAsyncComponents ( matched ) {
13621403 return flatMapComponents ( matched , function ( def , _ , match , key ) {
13631404 // if it's a function and doesn't have Vue options attached,
@@ -1588,10 +1629,10 @@ var HashHistory = (function (History) {
15881629 }
15891630
15901631 ensureSlash ( )
1591- this . transitionTo ( getHash ( ) )
1592-
1593- window . addEventListener ( 'hashchange' , function ( ) {
1594- this$1 . onHashChange ( )
1632+ this . transitionTo ( getHash ( ) , function ( ) {
1633+ window . addEventListener ( 'hashchange' , function ( ) {
1634+ this$1 . onHashChange ( )
1635+ } )
15951636 } )
15961637 }
15971638
@@ -1619,13 +1660,13 @@ var HashHistory = (function (History) {
16191660 } ;
16201661
16211662 HashHistory . prototype . push = function push ( location ) {
1622- History . prototype . transitionTo . call ( this , location , function ( route ) {
1663+ this . transitionTo ( location , function ( route ) {
16231664 pushHash ( route . fullPath )
16241665 } )
16251666 } ;
16261667
16271668 HashHistory . prototype . replace = function replace ( location ) {
1628- History . prototype . transitionTo . call ( this , location , function ( route ) {
1669+ this . transitionTo ( location , function ( route ) {
16291670 replaceHash ( route . fullPath )
16301671 } )
16311672 } ;
@@ -1678,7 +1719,7 @@ var AbstractHistory = (function (History) {
16781719 function AbstractHistory ( router ) {
16791720 History . call ( this , router )
16801721 this . stack = [ ]
1681- this . index = 0
1722+ this . index = - 1
16821723 }
16831724
16841725 if ( History ) AbstractHistory . __proto__ = History ;
@@ -1688,7 +1729,7 @@ var AbstractHistory = (function (History) {
16881729 AbstractHistory . prototype . push = function push ( location ) {
16891730 var this$1 = this ;
16901731
1691- History . prototype . transitionTo . call ( this , location , function ( route ) {
1732+ this . transitionTo ( location , function ( route ) {
16921733 this$1 . stack = this$1 . stack . slice ( 0 , this$1 . index + 1 ) . concat ( route )
16931734 this$1 . index ++
16941735 } )
@@ -1697,7 +1738,7 @@ var AbstractHistory = (function (History) {
16971738 AbstractHistory . prototype . replace = function replace ( location ) {
16981739 var this$1 = this ;
16991740
1700- History . prototype . transitionTo . call ( this , location , function ( route ) {
1741+ this . transitionTo ( location , function ( route ) {
17011742 this$1 . stack = this$1 . stack . slice ( 0 , this$1 . index ) . concat ( route )
17021743 } )
17031744 } ;
@@ -1709,10 +1750,10 @@ var AbstractHistory = (function (History) {
17091750 if ( targetIndex < 0 || targetIndex >= this . stack . length ) {
17101751 return
17111752 }
1712- var location = this . stack [ targetIndex ]
1713- this . confirmTransition ( location , function ( ) {
1753+ var route = this . stack [ targetIndex ]
1754+ this . confirmTransition ( route , function ( ) {
17141755 this$1 . index = targetIndex
1715- this$1 . updateRoute ( location )
1756+ this$1 . updateRoute ( route )
17161757 } )
17171758 } ;
17181759
0 commit comments