1
1
/**
2
- * vue-router v2.1.1
3
- * (c) 2016 Evan You
2
+ * vue-router v2.1.2
3
+ * (c) 2017 Evan You
4
4
* @license MIT
5
5
*/
6
6
'use strict' ;
@@ -22,11 +22,14 @@ var View = {
22
22
23
23
data . routerView = true
24
24
25
+ var name = props . name
25
26
var route = parent . $route
26
27
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.
27
31
var depth = 0
28
32
var inactive = false
29
-
30
33
while ( parent ) {
31
34
if ( parent . $vnode && parent . $vnode . data . routerView ) {
32
35
depth ++
@@ -36,30 +39,33 @@ var View = {
36
39
}
37
40
parent = parent . $parent
38
41
}
39
-
40
42
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
+
41
49
var matched = route . matched [ depth ]
50
+ // render empty node if no matched route
42
51
if ( ! matched ) {
52
+ cache [ name ] = null
43
53
return h ( )
44
54
}
45
55
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
63
69
}
64
70
}
65
71
@@ -171,6 +177,8 @@ function stringifyQuery (obj) {
171
177
172
178
/* */
173
179
180
+ var trailingSlashRE = / \/ ? $ /
181
+
174
182
function createRoute (
175
183
record ,
176
184
location ,
@@ -214,7 +222,6 @@ function getFullPath (ref) {
214
222
return ( path || '/' ) + stringifyQuery ( query ) + hash
215
223
}
216
224
217
- var trailingSlashRE = / \/ $ /
218
225
function isSameRoute ( a , b ) {
219
226
if ( b === START ) {
220
227
return a === b
@@ -252,7 +259,9 @@ function isObjectEqual (a, b) {
252
259
253
260
function isIncludedRoute ( current , target ) {
254
261
return (
255
- current . path . indexOf ( target . path . replace ( / \/ $ / , '' ) ) === 0 &&
262
+ current . path . replace ( trailingSlashRE , '/' ) . indexOf (
263
+ target . path . replace ( trailingSlashRE , '/' )
264
+ ) === 0 &&
256
265
( ! target . hash || current . hash === target . hash ) &&
257
266
queryIncludes ( current . query , target . query )
258
267
)
@@ -362,11 +371,13 @@ function guardEvent (e) {
362
371
if ( e . defaultPrevented ) { return }
363
372
// don't redirect on right click
364
373
/* istanbul ignore if */
365
- if ( e . button !== 0 ) { return }
374
+ if ( e . button !== undefined && e . button !== 0 ) { return }
366
375
// don't redirect if `target="_blank"`
367
376
/* 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
+ }
370
381
371
382
e . preventDefault ( )
372
383
return true
@@ -545,33 +556,55 @@ function addRouteRecord (
545
556
// not be rendered (GH Issue #629)
546
557
if ( process . env . NODE_ENV !== 'production' ) {
547
558
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."
549
566
)
550
567
}
551
568
}
552
569
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 )
554
574
} )
555
575
}
556
576
557
577
if ( route . alias !== undefined ) {
558
578
if ( Array . isArray ( route . alias ) ) {
559
579
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 )
561
585
} )
562
586
} 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 )
564
592
}
565
593
}
566
594
567
595
if ( ! pathMap [ record . path ] ) {
568
596
pathMap [ record . path ] = record
569
597
}
598
+
570
599
if ( name ) {
571
600
if ( ! nameMap [ name ] ) {
572
601
nameMap [ name ] = record
573
602
} 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
+ )
575
608
}
576
609
}
577
610
}
@@ -1132,6 +1165,9 @@ function createMatcher (routes) {
1132
1165
1133
1166
if ( name ) {
1134
1167
var record = nameMap [ name ]
1168
+ if ( process . env . NODE_ENV !== 'production' ) {
1169
+ warn ( record , ( "Route with name '" + name + "' does not exist" ) )
1170
+ }
1135
1171
var paramNames = getRouteRegex ( record . path ) . keys
1136
1172
. filter ( function ( key ) { return ! key . optional ; } )
1137
1173
. map ( function ( key ) { return key . name ; } )
@@ -1640,7 +1676,10 @@ function isNumber (v) {
1640
1676
/* */
1641
1677
1642
1678
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 ( ) ) ; }
1644
1683
var _key = genKey ( )
1645
1684
1646
1685
var HTML5History = ( function ( History ) {
@@ -1765,7 +1804,7 @@ function pushState (url, replace) {
1765
1804
}
1766
1805
saveScrollPosition ( _key )
1767
1806
} catch ( e ) {
1768
- window . location [ replace ? 'assign ' : 'replace ' ] ( url )
1807
+ window . location [ replace ? 'replace ' : 'assign ' ] ( url )
1769
1808
}
1770
1809
}
1771
1810
@@ -1867,8 +1906,8 @@ function replaceHash (path) {
1867
1906
1868
1907
1869
1908
var AbstractHistory = ( function ( History ) {
1870
- function AbstractHistory ( router ) {
1871
- History . call ( this , router )
1909
+ function AbstractHistory ( router , base ) {
1910
+ History . call ( this , router , base )
1872
1911
this . stack = [ ]
1873
1912
this . index = - 1
1874
1913
}
@@ -1944,7 +1983,7 @@ var VueRouter = function VueRouter (options) {
1944
1983
this . history = new HashHistory ( this , options . base , this . fallback )
1945
1984
break
1946
1985
case 'abstract' :
1947
- this . history = new AbstractHistory ( this )
1986
+ this . history = new AbstractHistory ( this , options . base )
1948
1987
break
1949
1988
default :
1950
1989
process . env . NODE_ENV !== 'production' && assert ( false , ( "invalid mode: " + mode ) )
@@ -2053,6 +2092,7 @@ function createHref (base, fullPath, mode) {
2053
2092
}
2054
2093
2055
2094
VueRouter . install = install
2095
+ VueRouter . version = '2.1.2'
2056
2096
2057
2097
if ( inBrowser && window . Vue ) {
2058
2098
window . Vue . use ( VueRouter )
0 commit comments