11/**
2- * vue-router v2.1.1
3- * (c) 2016 Evan You
2+ * vue-router v2.1.2
3+ * (c) 2017 Evan You
44 * @license MIT
55 */
66'use strict' ;
@@ -22,11 +22,14 @@ var View = {
2222
2323 data . routerView = true
2424
25+ var name = props . name
2526 var route = parent . $route
2627 var cache = parent . _routerViewCache || ( parent . _routerViewCache = { } )
28+
29+ // determine current view depth, also check to see if the tree
30+ // has been toggled inactive but kept-alive.
2731 var depth = 0
2832 var inactive = false
29-
3033 while ( parent ) {
3134 if ( parent . $vnode && parent . $vnode . data . routerView ) {
3235 depth ++
@@ -36,30 +39,33 @@ var View = {
3639 }
3740 parent = parent . $parent
3841 }
39-
4042 data . routerViewDepth = depth
43+
44+ // render previous view if the tree is inactive and kept-alive
45+ if ( inactive ) {
46+ return h ( cache [ name ] , data , children )
47+ }
48+
4149 var matched = route . matched [ depth ]
50+ // render empty node if no matched route
4251 if ( ! matched ) {
52+ cache [ name ] = null
4353 return h ( )
4454 }
4555
46- var name = props . name
47- var component = inactive
48- ? cache [ name ]
49- : ( cache [ name ] = matched . components [ name ] )
50-
51- if ( ! inactive ) {
52- var hooks = data . hook || ( data . hook = { } )
53- hooks . init = function ( vnode ) {
54- matched . instances [ name ] = vnode . child
55- }
56- hooks . prepatch = function ( oldVnode , vnode ) {
57- matched . instances [ name ] = vnode . child
58- }
59- hooks . destroy = function ( vnode ) {
60- if ( matched . instances [ name ] === vnode . child ) {
61- matched . instances [ name ] = undefined
62- }
56+ var component = cache [ name ] = matched . components [ name ]
57+
58+ // inject instance registration hooks
59+ var hooks = data . hook || ( data . hook = { } )
60+ hooks . init = function ( vnode ) {
61+ matched . instances [ name ] = vnode . child
62+ }
63+ hooks . prepatch = function ( oldVnode , vnode ) {
64+ matched . instances [ name ] = vnode . child
65+ }
66+ hooks . destroy = function ( vnode ) {
67+ if ( matched . instances [ name ] === vnode . child ) {
68+ matched . instances [ name ] = undefined
6369 }
6470 }
6571
@@ -171,6 +177,8 @@ function stringifyQuery (obj) {
171177
172178/* */
173179
180+ var trailingSlashRE = / \/ ? $ /
181+
174182function createRoute (
175183 record ,
176184 location ,
@@ -214,7 +222,6 @@ function getFullPath (ref) {
214222 return ( path || '/' ) + stringifyQuery ( query ) + hash
215223}
216224
217- var trailingSlashRE = / \/ $ /
218225function isSameRoute ( a , b ) {
219226 if ( b === START ) {
220227 return a === b
@@ -252,7 +259,9 @@ function isObjectEqual (a, b) {
252259
253260function isIncludedRoute ( current , target ) {
254261 return (
255- current . path . indexOf ( target . path . replace ( / \/ $ / , '' ) ) === 0 &&
262+ current . path . replace ( trailingSlashRE , '/' ) . indexOf (
263+ target . path . replace ( trailingSlashRE , '/' )
264+ ) === 0 &&
256265 ( ! target . hash || current . hash === target . hash ) &&
257266 queryIncludes ( current . query , target . query )
258267 )
@@ -362,11 +371,13 @@ function guardEvent (e) {
362371 if ( e . defaultPrevented ) { return }
363372 // don't redirect on right click
364373 /* istanbul ignore if */
365- if ( e . button !== 0 ) { return }
374+ if ( e . button !== undefined && e . button !== 0 ) { return }
366375 // don't redirect if `target="_blank"`
367376 /* istanbul ignore if */
368- var target = e . target . getAttribute ( 'target' )
369- if ( / \b _ b l a n k \b / i. test ( target ) ) { return }
377+ if ( e . target && e . target . getAttribute ) {
378+ var target = e . target . getAttribute ( 'target' )
379+ if ( / \b _ b l a n k \b / i. test ( target ) ) { return }
380+ }
370381
371382 e . preventDefault ( )
372383 return true
@@ -545,33 +556,55 @@ function addRouteRecord (
545556 // not be rendered (GH Issue #629)
546557 if ( process . env . NODE_ENV !== 'production' ) {
547558 if ( route . name && route . children . some ( function ( child ) { return / ^ \/ ? $ / . test ( child . path ) ; } ) ) {
548- warn ( false , ( "Named Route '" + ( route . name ) + "' has a default child route.\n When navigating to this named route (:to=\"{name: '" + ( route . name ) + "'\"), the default child route will not be rendered.\n Remove the name from this route and use the name of the default child route for named links instead." )
559+ warn (
560+ false ,
561+ "Named Route '" + ( route . name ) + "' has a default child route. " +
562+ "When navigating to this named route (:to=\"{name: '" + ( route . name ) + "'\"), " +
563+ "the default child route will not be rendered. Remove the name from " +
564+ "this route and use the name of the default child route for named " +
565+ "links instead."
549566 )
550567 }
551568 }
552569 route . children . forEach ( function ( child ) {
553- addRouteRecord ( pathMap , nameMap , child , record )
570+ var childMatchAs = matchAs
571+ ? cleanPath ( ( matchAs + "/" + ( child . path ) ) )
572+ : undefined
573+ addRouteRecord ( pathMap , nameMap , child , record , childMatchAs )
554574 } )
555575 }
556576
557577 if ( route . alias !== undefined ) {
558578 if ( Array . isArray ( route . alias ) ) {
559579 route . alias . forEach ( function ( alias ) {
560- addRouteRecord ( pathMap , nameMap , { path : alias } , parent , record . path )
580+ var aliasRoute = {
581+ path : alias ,
582+ children : route . children
583+ }
584+ addRouteRecord ( pathMap , nameMap , aliasRoute , parent , record . path )
561585 } )
562586 } else {
563- addRouteRecord ( pathMap , nameMap , { path : route . alias } , parent , record . path )
587+ var aliasRoute = {
588+ path : route . alias ,
589+ children : route . children
590+ }
591+ addRouteRecord ( pathMap , nameMap , aliasRoute , parent , record . path )
564592 }
565593 }
566594
567595 if ( ! pathMap [ record . path ] ) {
568596 pathMap [ record . path ] = record
569597 }
598+
570599 if ( name ) {
571600 if ( ! nameMap [ name ] ) {
572601 nameMap [ name ] = record
573602 } else if ( process . env . NODE_ENV !== 'production' ) {
574- warn ( false , ( "Duplicate named routes definition: { name: \"" + name + "\", path: \"" + ( record . path ) + "\" }" ) )
603+ warn (
604+ false ,
605+ "Duplicate named routes definition: " +
606+ "{ name: \"" + name + "\", path: \"" + ( record . path ) + "\" }"
607+ )
575608 }
576609 }
577610}
@@ -1132,6 +1165,9 @@ function createMatcher (routes) {
11321165
11331166 if ( name ) {
11341167 var record = nameMap [ name ]
1168+ if ( process . env . NODE_ENV !== 'production' ) {
1169+ warn ( record , ( "Route with name '" + name + "' does not exist" ) )
1170+ }
11351171 var paramNames = getRouteRegex ( record . path ) . keys
11361172 . filter ( function ( key ) { return ! key . optional ; } )
11371173 . map ( function ( key ) { return key . name ; } )
@@ -1640,7 +1676,10 @@ function isNumber (v) {
16401676/* */
16411677
16421678
1643- var genKey = function ( ) { return String ( Date . now ( ) ) ; }
1679+ // use User Timing api (if present) for more accurate key precision
1680+ var Time = inBrowser ? ( window . performance || Date ) : Date
1681+
1682+ var genKey = function ( ) { return String ( Time . now ( ) ) ; }
16441683var _key = genKey ( )
16451684
16461685var HTML5History = ( function ( History ) {
@@ -1765,7 +1804,7 @@ function pushState (url, replace) {
17651804 }
17661805 saveScrollPosition ( _key )
17671806 } catch ( e ) {
1768- window . location [ replace ? 'assign ' : 'replace ' ] ( url )
1807+ window . location [ replace ? 'replace ' : 'assign ' ] ( url )
17691808 }
17701809}
17711810
@@ -1867,8 +1906,8 @@ function replaceHash (path) {
18671906
18681907
18691908var AbstractHistory = ( function ( History ) {
1870- function AbstractHistory ( router ) {
1871- History . call ( this , router )
1909+ function AbstractHistory ( router , base ) {
1910+ History . call ( this , router , base )
18721911 this . stack = [ ]
18731912 this . index = - 1
18741913 }
@@ -1944,7 +1983,7 @@ var VueRouter = function VueRouter (options) {
19441983 this . history = new HashHistory ( this , options . base , this . fallback )
19451984 break
19461985 case 'abstract' :
1947- this . history = new AbstractHistory ( this )
1986+ this . history = new AbstractHistory ( this , options . base )
19481987 break
19491988 default :
19501989 process . env . NODE_ENV !== 'production' && assert ( false , ( "invalid mode: " + mode ) )
@@ -2053,6 +2092,7 @@ function createHref (base, fullPath, mode) {
20532092}
20542093
20552094VueRouter . install = install
2095+ VueRouter . version = '2.1.2'
20562096
20572097if ( inBrowser && window . Vue ) {
20582098 window . Vue . use ( VueRouter )
0 commit comments