1
- /**
2
- * vue-router v3.0.1
3
- * (c) 2017 Evan You
1
+ /*!
2
+ * vue-router v3.0.2
3
+ * (c) 2018 Evan You
4
4
* @license MIT
5
5
*/
6
6
'use strict' ;
@@ -23,8 +23,15 @@ function isError (err) {
23
23
return Object . prototype . toString . call ( err ) . indexOf ( 'Error' ) > - 1
24
24
}
25
25
26
+ function extend ( a , b ) {
27
+ for ( var key in b ) {
28
+ a [ key ] = b [ key ] ;
29
+ }
30
+ return a
31
+ }
32
+
26
33
var View = {
27
- name : 'router-view ' ,
34
+ name : 'RouterView ' ,
28
35
functional : true ,
29
36
props : {
30
37
name : {
@@ -38,6 +45,7 @@ var View = {
38
45
var parent = ref . parent ;
39
46
var data = ref . data ;
40
47
48
+ // used by devtools to display a router-view badge
41
49
data . routerView = true ;
42
50
43
51
// directly use parent context's createElement() function
@@ -112,7 +120,7 @@ var View = {
112
120
113
121
return h ( component , data , children )
114
122
}
115
- } ;
123
+ }
116
124
117
125
function resolveProps ( route , config ) {
118
126
switch ( typeof config ) {
@@ -135,13 +143,6 @@ function resolveProps (route, config) {
135
143
}
136
144
}
137
145
138
- function extend ( to , from ) {
139
- for ( var key in from ) {
140
- to [ key ] = from [ key ] ;
141
- }
142
- return to
143
- }
144
-
145
146
/* */
146
147
147
148
var encodeReserveRE = / [ ! ' ( ) * ] / g;
@@ -240,7 +241,6 @@ function stringifyQuery (obj) {
240
241
241
242
/* */
242
243
243
-
244
244
var trailingSlashRE = / \/ ? $ / ;
245
245
246
246
function createRoute (
@@ -383,7 +383,7 @@ var toTypes = [String, Object];
383
383
var eventTypes = [ String , Array ] ;
384
384
385
385
var Link = {
386
- name : 'router-link ' ,
386
+ name : 'RouterLink ' ,
387
387
props : {
388
388
to : {
389
389
type : toTypes ,
@@ -418,17 +418,17 @@ var Link = {
418
418
var globalExactActiveClass = router . options . linkExactActiveClass ;
419
419
// Support global empty active class
420
420
var activeClassFallback = globalActiveClass == null
421
- ? 'router-link-active'
422
- : globalActiveClass ;
421
+ ? 'router-link-active'
422
+ : globalActiveClass ;
423
423
var exactActiveClassFallback = globalExactActiveClass == null
424
- ? 'router-link-exact-active'
425
- : globalExactActiveClass ;
424
+ ? 'router-link-exact-active'
425
+ : globalExactActiveClass ;
426
426
var activeClass = this . activeClass == null
427
- ? activeClassFallback
428
- : this . activeClass ;
427
+ ? activeClassFallback
428
+ : this . activeClass ;
429
429
var exactActiveClass = this . exactActiveClass == null
430
- ? exactActiveClassFallback
431
- : this . exactActiveClass ;
430
+ ? exactActiveClassFallback
431
+ : this . exactActiveClass ;
432
432
var compareTarget = location . path
433
433
? createRoute ( null , location , null , router )
434
434
: route ;
@@ -468,7 +468,6 @@ var Link = {
468
468
if ( a ) {
469
469
// in case the <a> is a static node
470
470
a . isStatic = false ;
471
- var extend = _Vue . util . extend ;
472
471
var aData = a . data = extend ( { } , a . data ) ;
473
472
aData . on = on ;
474
473
var aAttrs = a . data . attrs = extend ( { } , a . data . attrs ) ;
@@ -481,7 +480,7 @@ var Link = {
481
480
482
481
return h ( this . tag , data , this . $slots . default )
483
482
}
484
- } ;
483
+ }
485
484
486
485
function guardEvent ( e ) {
487
486
// don't redirect with control keys
@@ -559,8 +558,8 @@ function install (Vue) {
559
558
get : function get ( ) { return this . _routerRoot . _route }
560
559
} ) ;
561
560
562
- Vue . component ( 'router-view ' , View ) ;
563
- Vue . component ( 'router-link ' , Link ) ;
561
+ Vue . component ( 'RouterView ' , View ) ;
562
+ Vue . component ( 'RouterLink ' , Link ) ;
564
563
565
564
var strats = Vue . config . optionMergeStrategies ;
566
565
// use the same hook merging strategy for route hooks
@@ -1070,7 +1069,6 @@ function pathToRegexp (path, keys, options) {
1070
1069
1071
1070
return stringToRegexp ( /** @type {string } */ ( path ) , /** @type {!Array } */ ( keys ) , options )
1072
1071
}
1073
-
1074
1072
pathToRegexp_1 . parse = parse_1 ;
1075
1073
pathToRegexp_1 . compile = compile_1 ;
1076
1074
pathToRegexp_1 . tokensToFunction = tokensToFunction_1 ;
@@ -1266,7 +1264,6 @@ function normalizePath (path, parent, strict) {
1266
1264
1267
1265
/* */
1268
1266
1269
-
1270
1267
function normalizeLocation (
1271
1268
raw ,
1272
1269
current ,
@@ -1281,9 +1278,9 @@ function normalizeLocation (
1281
1278
1282
1279
// relative params
1283
1280
if ( ! next . path && next . params && current ) {
1284
- next = assign ( { } , next ) ;
1281
+ next = extend ( { } , next ) ;
1285
1282
next . _normalized = true ;
1286
- var params = assign ( assign ( { } , current . params ) , next . params ) ;
1283
+ var params = extend ( extend ( { } , current . params ) , next . params ) ;
1287
1284
if ( current . name ) {
1288
1285
next . name = current . name ;
1289
1286
next . params = params ;
@@ -1321,16 +1318,10 @@ function normalizeLocation (
1321
1318
}
1322
1319
}
1323
1320
1324
- function assign ( a , b ) {
1325
- for ( var key in b ) {
1326
- a [ key ] = b [ key ] ;
1327
- }
1328
- return a
1329
- }
1330
-
1331
1321
/* */
1332
1322
1333
1323
1324
+
1334
1325
function createMatcher (
1335
1326
routes ,
1336
1327
router
@@ -1398,8 +1389,8 @@ function createMatcher (
1398
1389
) {
1399
1390
var originalRedirect = record . redirect ;
1400
1391
var redirect = typeof originalRedirect === 'function'
1401
- ? originalRedirect ( createRoute ( record , location , null , router ) )
1402
- : originalRedirect ;
1392
+ ? originalRedirect ( createRoute ( record , location , null , router ) )
1393
+ : originalRedirect ;
1403
1394
1404
1395
if ( typeof redirect === 'string' ) {
1405
1396
redirect = { path : redirect } ;
@@ -1513,7 +1504,8 @@ function matchRoute (
1513
1504
var key = regex . keys [ i - 1 ] ;
1514
1505
var val = typeof m [ i ] === 'string' ? decodeURIComponent ( m [ i ] ) : m [ i ] ;
1515
1506
if ( key ) {
1516
- params [ key . name ] = val ;
1507
+ // Fix #1994: using * with props: true generates a param named 0
1508
+ params [ key . name || 'pathMatch' ] = val ;
1517
1509
}
1518
1510
}
1519
1511
@@ -1526,12 +1518,12 @@ function resolveRecordPath (path, record) {
1526
1518
1527
1519
/* */
1528
1520
1529
-
1530
1521
var positionStore = Object . create ( null ) ;
1531
1522
1532
1523
function setupScroll ( ) {
1533
1524
// Fix for #1585 for Firefox
1534
- window . history . replaceState ( { key : getStateKey ( ) } , '' ) ;
1525
+ // Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1526
+ window . history . replaceState ( { key : getStateKey ( ) } , '' , window . location . href . replace ( window . location . origin , '' ) ) ;
1535
1527
window . addEventListener ( 'popstate' , function ( e ) {
1536
1528
saveScrollPosition ( ) ;
1537
1529
if ( e . state && e . state . key ) {
@@ -1562,7 +1554,7 @@ function handleScroll (
1562
1554
// wait until re-render finishes before scrolling
1563
1555
router . app . $nextTick ( function ( ) {
1564
1556
var position = getScrollPosition ( ) ;
1565
- var shouldScroll = behavior ( to , from , isPop ? position : null ) ;
1557
+ var shouldScroll = behavior . call ( router , to , from , isPop ? position : null ) ;
1566
1558
1567
1559
if ( ! shouldScroll ) {
1568
1560
return
@@ -2124,7 +2116,10 @@ function poll (
2124
2116
key ,
2125
2117
isValid
2126
2118
) {
2127
- if ( instances [ key ] ) {
2119
+ if (
2120
+ instances [ key ] &&
2121
+ ! instances [ key ] . _isBeingDestroyed // do not reuse being destroyed instance
2122
+ ) {
2128
2123
cb ( instances [ key ] ) ;
2129
2124
} else if ( isValid ( ) ) {
2130
2125
setTimeout ( function ( ) {
@@ -2135,16 +2130,16 @@ function poll (
2135
2130
2136
2131
/* */
2137
2132
2138
-
2139
2133
var HTML5History = ( function ( History$$1 ) {
2140
2134
function HTML5History ( router , base ) {
2141
2135
var this$1 = this ;
2142
2136
2143
2137
History$$1 . call ( this , router , base ) ;
2144
2138
2145
2139
var expectScroll = router . options . scrollBehavior ;
2140
+ var supportsScroll = supportsPushState && expectScroll ;
2146
2141
2147
- if ( expectScroll ) {
2142
+ if ( supportsScroll ) {
2148
2143
setupScroll ( ) ;
2149
2144
}
2150
2145
@@ -2160,7 +2155,7 @@ var HTML5History = (function (History$$1) {
2160
2155
}
2161
2156
2162
2157
this$1 . transitionTo ( location , function ( route ) {
2163
- if ( expectScroll ) {
2158
+ if ( supportsScroll ) {
2164
2159
handleScroll ( router , route , current , true ) ;
2165
2160
}
2166
2161
} ) ;
@@ -2214,7 +2209,7 @@ var HTML5History = (function (History$$1) {
2214
2209
} ( History ) ) ;
2215
2210
2216
2211
function getLocation ( base ) {
2217
- var path = window . location . pathname ;
2212
+ var path = decodeURI ( window . location . pathname ) ;
2218
2213
if ( base && path . indexOf ( base ) === 0 ) {
2219
2214
path = path . slice ( base . length ) ;
2220
2215
}
@@ -2223,7 +2218,6 @@ function getLocation (base) {
2223
2218
2224
2219
/* */
2225
2220
2226
-
2227
2221
var HashHistory = ( function ( History$$1 ) {
2228
2222
function HashHistory ( router , base , fallback ) {
2229
2223
History$$1 . call ( this , router , base ) ;
@@ -2333,7 +2327,7 @@ function getHash () {
2333
2327
// consistent across browsers - Firefox will pre-decode it!
2334
2328
var href = window . location . href ;
2335
2329
var index = href . indexOf ( '#' ) ;
2336
- return index === - 1 ? '' : href . slice ( index + 1 )
2330
+ return index === - 1 ? '' : decodeURI ( href . slice ( index + 1 ) )
2337
2331
}
2338
2332
2339
2333
function getUrl ( path ) {
@@ -2361,7 +2355,6 @@ function replaceHash (path) {
2361
2355
2362
2356
/* */
2363
2357
2364
-
2365
2358
var AbstractHistory = ( function ( History$$1 ) {
2366
2359
function AbstractHistory ( router , base ) {
2367
2360
History$$1 . call ( this , router , base ) ;
@@ -2420,6 +2413,8 @@ var AbstractHistory = (function (History$$1) {
2420
2413
2421
2414
/* */
2422
2415
2416
+
2417
+
2423
2418
var VueRouter = function VueRouter ( options ) {
2424
2419
if ( options === void 0 ) options = { } ;
2425
2420
@@ -2616,7 +2611,7 @@ function createHref (base, fullPath, mode) {
2616
2611
}
2617
2612
2618
2613
VueRouter . install = install ;
2619
- VueRouter . version = '3.0.1 ' ;
2614
+ VueRouter . version = '3.0.2 ' ;
2620
2615
2621
2616
if ( inBrowser && window . Vue ) {
2622
2617
window . Vue . use ( VueRouter ) ;
0 commit comments