1
1
/**
2
- * vue-router v2.5.3
2
+ * vue-router v2.6.0
3
3
* (c) 2017 Evan You
4
4
* @license MIT
5
5
*/
@@ -47,7 +47,7 @@ var View = {
47
47
// has been toggled inactive but kept-alive.
48
48
var depth = 0 ;
49
49
var inactive = false ;
50
- while ( parent ) {
50
+ while ( parent && parent . _routerRoot !== parent ) {
51
51
if ( parent . $vnode && parent . $vnode . data . routerView ) {
52
52
depth ++ ;
53
53
}
@@ -198,7 +198,7 @@ function stringifyQuery (obj) {
198
198
199
199
if ( Array . isArray ( val ) ) {
200
200
var result = [ ] ;
201
- val . slice ( ) . forEach ( function ( val2 ) {
201
+ val . forEach ( function ( val2 ) {
202
202
if ( val2 === undefined ) {
203
203
return
204
204
}
@@ -302,7 +302,15 @@ function isObjectEqual (a, b) {
302
302
if ( aKeys . length !== bKeys . length ) {
303
303
return false
304
304
}
305
- return aKeys . every ( function ( key ) { return String ( a [ key ] ) === String ( b [ key ] ) ; } )
305
+ return aKeys . every ( function ( key ) {
306
+ var aVal = a [ key ] ;
307
+ var bVal = b [ key ] ;
308
+ // check nested equality
309
+ if ( typeof aVal === 'object' && typeof bVal === 'object' ) {
310
+ return isObjectEqual ( aVal , bVal )
311
+ }
312
+ return String ( aVal ) === String ( bVal )
313
+ } )
306
314
}
307
315
308
316
function isIncludedRoute ( current , target ) {
@@ -433,7 +441,7 @@ var Link = {
433
441
434
442
function guardEvent ( e ) {
435
443
// don't redirect with control keys
436
- if ( e . metaKey || e . ctrlKey || e . shiftKey ) { return }
444
+ if ( e . metaKey || e . altKey || e . ctrlKey || e . shiftKey ) { return }
437
445
// don't redirect when preventDefault called
438
446
if ( e . defaultPrevented ) { return }
439
447
// don't redirect on right click
@@ -473,14 +481,6 @@ function install (Vue) {
473
481
474
482
_Vue = Vue ;
475
483
476
- Object . defineProperty ( Vue . prototype , '$router' , {
477
- get : function get ( ) { return this . $root . _router }
478
- } ) ;
479
-
480
- Object . defineProperty ( Vue . prototype , '$route' , {
481
- get : function get ( ) { return this . $root . _route }
482
- } ) ;
483
-
484
484
var isDef = function ( v ) { return v !== undefined ; } ;
485
485
486
486
var registerInstance = function ( vm , callVal ) {
@@ -493,9 +493,12 @@ function install (Vue) {
493
493
Vue . mixin ( {
494
494
beforeCreate : function beforeCreate ( ) {
495
495
if ( isDef ( this . $options . router ) ) {
496
+ this . _routerRoot = this ;
496
497
this . _router = this . $options . router ;
497
498
this . _router . init ( this ) ;
498
499
Vue . util . defineReactive ( this , '_route' , this . _router . history . current ) ;
500
+ } else {
501
+ this . _routerRoot = ( this . $parent && this . $parent . _routerRoot ) || this ;
499
502
}
500
503
registerInstance ( this , this ) ;
501
504
} ,
@@ -504,6 +507,14 @@ function install (Vue) {
504
507
}
505
508
} ) ;
506
509
510
+ Object . defineProperty ( Vue . prototype , '$router' , {
511
+ get : function get ( ) { return this . _routerRoot . _router }
512
+ } ) ;
513
+
514
+ Object . defineProperty ( Vue . prototype , '$route' , {
515
+ get : function get ( ) { return this . _routerRoot . _route }
516
+ } ) ;
517
+
507
518
Vue . component ( 'router-view' , View ) ;
508
519
Vue . component ( 'router-link' , Link ) ;
509
520
@@ -1096,9 +1107,15 @@ function addRouteRecord (
1096
1107
}
1097
1108
1098
1109
var normalizedPath = normalizePath ( path , parent ) ;
1110
+ var pathToRegexpOptions = route . pathToRegexpOptions || { } ;
1111
+
1112
+ if ( typeof route . caseSensitive === 'boolean' ) {
1113
+ pathToRegexpOptions . sensitive = route . caseSensitive ;
1114
+ }
1115
+
1099
1116
var record = {
1100
1117
path : normalizedPath ,
1101
- regex : compileRouteRegex ( normalizedPath ) ,
1118
+ regex : compileRouteRegex ( normalizedPath , pathToRegexpOptions ) ,
1102
1119
components : route . components || { default : route . component } ,
1103
1120
instances : { } ,
1104
1121
name : name ,
@@ -1115,11 +1132,11 @@ function addRouteRecord (
1115
1132
} ;
1116
1133
1117
1134
if ( route . children ) {
1118
- // Warn if route is named and has a default child route.
1135
+ // Warn if route is named, does not redirect and has a default child route.
1119
1136
// If users navigate to this route by name, the default child will
1120
1137
// not be rendered (GH Issue #629)
1121
1138
if ( process . env . NODE_ENV !== 'production' ) {
1122
- if ( route . name && route . children . some ( function ( child ) { return / ^ \/ ? $ / . test ( child . path ) ; } ) ) {
1139
+ if ( route . name && ! route . redirect && route . children . some ( function ( child ) { return / ^ \/ ? $ / . test ( child . path ) ; } ) ) {
1123
1140
warn (
1124
1141
false ,
1125
1142
"Named Route '" + ( route . name ) + "' has a default child route. " +
@@ -1139,21 +1156,24 @@ function addRouteRecord (
1139
1156
}
1140
1157
1141
1158
if ( route . alias !== undefined ) {
1142
- if ( Array . isArray ( route . alias ) ) {
1143
- route . alias . forEach ( function ( alias ) {
1144
- var aliasRoute = {
1145
- path : alias ,
1146
- children : route . children
1147
- } ;
1148
- addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path ) ;
1149
- } ) ;
1150
- } else {
1159
+ var aliases = Array . isArray ( route . alias )
1160
+ ? route . alias
1161
+ : [ route . alias ] ;
1162
+
1163
+ aliases . forEach ( function ( alias ) {
1151
1164
var aliasRoute = {
1152
- path : route . alias ,
1165
+ path : alias ,
1153
1166
children : route . children
1154
1167
} ;
1155
- addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path ) ;
1156
- }
1168
+ addRouteRecord (
1169
+ pathList ,
1170
+ pathMap ,
1171
+ nameMap ,
1172
+ aliasRoute ,
1173
+ parent ,
1174
+ record . path || '/' // matchAs
1175
+ ) ;
1176
+ } ) ;
1157
1177
}
1158
1178
1159
1179
if ( ! pathMap [ record . path ] ) {
@@ -1174,8 +1194,8 @@ function addRouteRecord (
1174
1194
}
1175
1195
}
1176
1196
1177
- function compileRouteRegex ( path ) {
1178
- var regex = index ( path ) ;
1197
+ function compileRouteRegex ( path , pathToRegexpOptions ) {
1198
+ var regex = index ( path , [ ] , pathToRegexpOptions ) ;
1179
1199
if ( process . env . NODE_ENV !== 'production' ) {
1180
1200
var keys = { } ;
1181
1201
regex . keys . forEach ( function ( key ) {
@@ -1216,7 +1236,7 @@ function normalizeLocation (
1216
1236
if ( current . name ) {
1217
1237
next . name = current . name ;
1218
1238
next . params = params ;
1219
- } else if ( current . matched ) {
1239
+ } else if ( current . matched . length ) {
1220
1240
var rawPath = current . matched [ current . matched . length - 1 ] . path ;
1221
1241
next . path = fillParams ( rawPath , params , ( "path " + ( current . path ) ) ) ;
1222
1242
} else if ( process . env . NODE_ENV !== 'production' ) {
@@ -1286,6 +1306,7 @@ function createMatcher (
1286
1306
if ( process . env . NODE_ENV !== 'production' ) {
1287
1307
warn ( record , ( "Route with name '" + name + "' does not exist" ) ) ;
1288
1308
}
1309
+ if ( ! record ) { return _createRoute ( null , location ) }
1289
1310
var paramNames = record . regex . keys
1290
1311
. filter ( function ( key ) { return ! key . optional ; } )
1291
1312
. map ( function ( key ) { return key . name ; } ) ;
@@ -1496,7 +1517,9 @@ function handleScroll (
1496
1517
if ( isObject && typeof shouldScroll . selector === 'string' ) {
1497
1518
var el = document . querySelector ( shouldScroll . selector ) ;
1498
1519
if ( el ) {
1499
- position = getElementPosition ( el ) ;
1520
+ var offset = shouldScroll . offset && typeof shouldScroll . offset === 'object' ? shouldScroll . offset : { } ;
1521
+ offset = normalizeOffset ( offset ) ;
1522
+ position = getElementPosition ( el , offset ) ;
1500
1523
} else if ( isValidPosition ( shouldScroll ) ) {
1501
1524
position = normalizePosition ( shouldScroll ) ;
1502
1525
}
@@ -1527,13 +1550,13 @@ function getScrollPosition () {
1527
1550
}
1528
1551
}
1529
1552
1530
- function getElementPosition ( el ) {
1553
+ function getElementPosition ( el , offset ) {
1531
1554
var docEl = document . documentElement ;
1532
1555
var docRect = docEl . getBoundingClientRect ( ) ;
1533
1556
var elRect = el . getBoundingClientRect ( ) ;
1534
1557
return {
1535
- x : elRect . left - docRect . left ,
1536
- y : elRect . top - docRect . top
1558
+ x : elRect . left - docRect . left - offset . x ,
1559
+ y : elRect . top - docRect . top - offset . y
1537
1560
}
1538
1561
}
1539
1562
@@ -1548,6 +1571,13 @@ function normalizePosition (obj) {
1548
1571
}
1549
1572
}
1550
1573
1574
+ function normalizeOffset ( obj ) {
1575
+ return {
1576
+ x : isNumber ( obj . x ) ? obj . x : 0 ,
1577
+ y : isNumber ( obj . y ) ? obj . y : 0
1578
+ }
1579
+ }
1580
+
1551
1581
function isNumber ( v ) {
1552
1582
return typeof v === 'number'
1553
1583
}
@@ -1800,6 +1830,8 @@ function normalizeBase (base) {
1800
1830
// respect <base> tag
1801
1831
var baseEl = document . querySelector ( 'base' ) ;
1802
1832
base = ( baseEl && baseEl . getAttribute ( 'href' ) ) || '/' ;
1833
+ // strip full URL origin
1834
+ base = base . replace ( / ^ h t t p s ? : \/ \/ [ ^ \/ ] + / , '' ) ;
1803
1835
} else {
1804
1836
base = '/' ;
1805
1837
}
@@ -2010,9 +2042,12 @@ function flatten (arr) {
2010
2042
function once ( fn ) {
2011
2043
var called = false ;
2012
2044
return function ( ) {
2045
+ var args = [ ] , len = arguments . length ;
2046
+ while ( len -- ) args [ len ] = arguments [ len ] ;
2047
+
2013
2048
if ( called ) { return }
2014
2049
called = true ;
2015
- return fn . apply ( this , arguments )
2050
+ return fn . apply ( this , args )
2016
2051
}
2017
2052
}
2018
2053
@@ -2036,9 +2071,10 @@ var HTML5History = (function (History$$1) {
2036
2071
}
2037
2072
2038
2073
window . addEventListener ( 'popstate' , function ( e ) {
2074
+ var current = this$1 . current ;
2039
2075
this$1 . transitionTo ( getLocation ( this$1 . base ) , function ( route ) {
2040
2076
if ( expectScroll ) {
2041
- handleScroll ( router , route , this$1 . current , true ) ;
2077
+ handleScroll ( router , route , current , true ) ;
2042
2078
}
2043
2079
} ) ;
2044
2080
} ) ;
@@ -2194,10 +2230,10 @@ function pushHash (path) {
2194
2230
}
2195
2231
2196
2232
function replaceHash ( path ) {
2197
- var i = window . location . href . indexOf ( '#' ) ;
2198
- window . location . replace (
2199
- window . location . href . slice ( 0 , i >= 0 ? i : 0 ) + '#' + path
2200
- ) ;
2233
+ var href = window . location . href ;
2234
+ var i = href . indexOf ( '#' ) ;
2235
+ var base = i >= 0 ? href . slice ( 0 , i ) : href ;
2236
+ window . location . replace ( ( base + "#" + path ) ) ;
2201
2237
}
2202
2238
2203
2239
/* */
@@ -2273,7 +2309,7 @@ var VueRouter = function VueRouter (options) {
2273
2309
this . matcher = createMatcher ( options . routes || [ ] , this ) ;
2274
2310
2275
2311
var mode = options . mode || 'hash' ;
2276
- this . fallback = mode === 'history' && ! supportsPushState ;
2312
+ this . fallback = mode === 'history' && ! supportsPushState && options . fallback !== false ;
2277
2313
if ( this . fallback ) {
2278
2314
mode = 'hash' ;
2279
2315
}
@@ -2457,7 +2493,7 @@ function createHref (base, fullPath, mode) {
2457
2493
}
2458
2494
2459
2495
VueRouter . install = install ;
2460
- VueRouter . version = '2.5.3 ' ;
2496
+ VueRouter . version = '2.6.0 ' ;
2461
2497
2462
2498
if ( inBrowser && window . Vue ) {
2463
2499
window . Vue . use ( VueRouter ) ;
0 commit comments