1
1
/*!
2
- * vue-router v3.4.9
3
- * (c) 2020 Evan You
2
+ * vue-router v3.5.0
3
+ * (c) 2021 Evan You
4
4
* @license MIT
5
5
*/
6
6
'use strict' ;
@@ -212,23 +212,23 @@ function getFullPath (
212
212
return ( path || '/' ) + stringify ( query ) + hash
213
213
}
214
214
215
- function isSameRoute ( a , b ) {
215
+ function isSameRoute ( a , b , onlyPath ) {
216
216
if ( b === START ) {
217
217
return a === b
218
218
} else if ( ! b ) {
219
219
return false
220
220
} else if ( a . path && b . path ) {
221
- return (
222
- a . path . replace ( trailingSlashRE , '' ) === b . path . replace ( trailingSlashRE , '' ) &&
221
+ return a . path . replace ( trailingSlashRE , '' ) === b . path . replace ( trailingSlashRE , '' ) && ( onlyPath ||
223
222
a . hash === b . hash &&
224
- isObjectEqual ( a . query , b . query )
225
- )
223
+ isObjectEqual ( a . query , b . query ) )
226
224
} else if ( a . name && b . name ) {
227
225
return (
228
226
a . name === b . name &&
229
- a . hash === b . hash &&
227
+ ( onlyPath || (
228
+ a . hash === b . hash &&
230
229
isObjectEqual ( a . query , b . query ) &&
231
- isObjectEqual ( a . params , b . params )
230
+ isObjectEqual ( a . params , b . params ) )
231
+ )
232
232
)
233
233
} else {
234
234
return false
@@ -1060,6 +1060,10 @@ var eventTypes = [String, Array];
1060
1060
1061
1061
var noop = function ( ) { } ;
1062
1062
1063
+ var warnedCustomSlot ;
1064
+ var warnedTagProp ;
1065
+ var warnedEventProp ;
1066
+
1063
1067
var Link = {
1064
1068
name : 'RouterLink' ,
1065
1069
props : {
@@ -1071,7 +1075,9 @@ var Link = {
1071
1075
type : String ,
1072
1076
default : 'a'
1073
1077
} ,
1078
+ custom : Boolean ,
1074
1079
exact : Boolean ,
1080
+ exactPath : Boolean ,
1075
1081
append : Boolean ,
1076
1082
replace : Boolean ,
1077
1083
activeClass : String ,
@@ -1120,8 +1126,8 @@ var Link = {
1120
1126
? createRoute ( null , normalizeLocation ( route . redirectedFrom ) , null , router )
1121
1127
: route ;
1122
1128
1123
- classes [ exactActiveClass ] = isSameRoute ( current , compareTarget ) ;
1124
- classes [ activeClass ] = this . exact
1129
+ classes [ exactActiveClass ] = isSameRoute ( current , compareTarget , this . exactPath ) ;
1130
+ classes [ activeClass ] = this . exact || this . exactPath
1125
1131
? classes [ exactActiveClass ]
1126
1132
: isIncludedRoute ( current , compareTarget ) ;
1127
1133
@@ -1160,19 +1166,40 @@ var Link = {
1160
1166
} ) ;
1161
1167
1162
1168
if ( scopedSlot ) {
1169
+ if ( process . env . NODE_ENV !== 'production' && ! this . custom ) {
1170
+ ! warnedCustomSlot && warn ( false , 'In Vue Router 4, the v-slot API will by default wrap its content with an <a> element. Use the custom prop to remove this warning:\n<router-link v-slot="{ navigate, href }" custom></router-link>\n' ) ;
1171
+ warnedCustomSlot = true ;
1172
+ }
1163
1173
if ( scopedSlot . length === 1 ) {
1164
1174
return scopedSlot [ 0 ]
1165
1175
} else if ( scopedSlot . length > 1 || ! scopedSlot . length ) {
1166
1176
if ( process . env . NODE_ENV !== 'production' ) {
1167
1177
warn (
1168
1178
false ,
1169
- ( "RouterLink with to=\"" + ( this . to ) + "\" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element." )
1179
+ ( "<router-link> with to=\"" + ( this . to ) + "\" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element." )
1170
1180
) ;
1171
1181
}
1172
1182
return scopedSlot . length === 0 ? h ( ) : h ( 'span' , { } , scopedSlot )
1173
1183
}
1174
1184
}
1175
1185
1186
+ if ( process . env . NODE_ENV !== 'production' ) {
1187
+ if ( this . tag && ! warnedTagProp ) {
1188
+ warn (
1189
+ false ,
1190
+ "<router-link>'s tag prop is deprecated and has been removed in Vue Router 4. Use the v-slot API to remove this warning: https://next.router.vuejs.org/guide/migration/#removal-of-event-and-tag-props-in-router-link."
1191
+ ) ;
1192
+ warnedTagProp = true ;
1193
+ }
1194
+ if ( this . event && ! warnedEventProp ) {
1195
+ warn (
1196
+ false ,
1197
+ "<router-link>'s event prop is deprecated and has been removed in Vue Router 4. Use the v-slot API to remove this warning: https://next.router.vuejs.org/guide/migration/#removal-of-event-and-tag-props-in-router-link."
1198
+ ) ;
1199
+ warnedEventProp = true ;
1200
+ }
1201
+ }
1202
+
1176
1203
if ( this . tag === 'a' ) {
1177
1204
data . on = on ;
1178
1205
data . attrs = { href : href , 'aria-current' : ariaCurrentValue } ;
@@ -1308,7 +1335,8 @@ function createRouteMap (
1308
1335
routes ,
1309
1336
oldPathList ,
1310
1337
oldPathMap ,
1311
- oldNameMap
1338
+ oldNameMap ,
1339
+ parentRoute
1312
1340
) {
1313
1341
// the path list is used to control path matching priority
1314
1342
var pathList = oldPathList || [ ] ;
@@ -1318,7 +1346,7 @@ function createRouteMap (
1318
1346
var nameMap = oldNameMap || Object . create ( null ) ;
1319
1347
1320
1348
routes . forEach ( function ( route ) {
1321
- addRouteRecord ( pathList , pathMap , nameMap , route ) ;
1349
+ addRouteRecord ( pathList , pathMap , nameMap , route , parentRoute ) ;
1322
1350
} ) ;
1323
1351
1324
1352
// ensure wildcard routes are always at the end
@@ -1389,6 +1417,11 @@ function addRouteRecord (
1389
1417
path : normalizedPath ,
1390
1418
regex : compileRouteRegex ( normalizedPath , pathToRegexpOptions ) ,
1391
1419
components : route . components || { default : route . component } ,
1420
+ alias : route . alias
1421
+ ? typeof route . alias === 'string'
1422
+ ? [ route . alias ]
1423
+ : route . alias
1424
+ : [ ] ,
1392
1425
instances : { } ,
1393
1426
enteredCbs : { } ,
1394
1427
name : name ,
@@ -1525,6 +1558,28 @@ function createMatcher (
1525
1558
createRouteMap ( routes , pathList , pathMap , nameMap ) ;
1526
1559
}
1527
1560
1561
+ function addRoute ( parentOrRoute , route ) {
1562
+ var parent = ( typeof parentOrRoute !== 'object' ) ? nameMap [ parentOrRoute ] : undefined ;
1563
+ // $flow-disable-line
1564
+ createRouteMap ( [ route || parentOrRoute ] , pathList , pathMap , nameMap , parent ) ;
1565
+
1566
+ // add aliases of parent
1567
+ if ( parent ) {
1568
+ createRouteMap (
1569
+ // $flow-disable-line route is defined if parent is
1570
+ parent . alias . map ( function ( alias ) { return ( { path : alias , children : [ route ] } ) ; } ) ,
1571
+ pathList ,
1572
+ pathMap ,
1573
+ nameMap ,
1574
+ parent
1575
+ ) ;
1576
+ }
1577
+ }
1578
+
1579
+ function getRoutes ( ) {
1580
+ return pathList . map ( function ( path ) { return pathMap [ path ] ; } )
1581
+ }
1582
+
1528
1583
function match (
1529
1584
raw ,
1530
1585
currentRoute ,
@@ -1671,6 +1726,8 @@ function createMatcher (
1671
1726
1672
1727
return {
1673
1728
match : match ,
1729
+ addRoute : addRoute ,
1730
+ getRoutes : getRoutes ,
1674
1731
addRoutes : addRoutes
1675
1732
}
1676
1733
}
@@ -3034,7 +3091,21 @@ VueRouter.prototype.resolve = function resolve (
3034
3091
}
3035
3092
} ;
3036
3093
3094
+ VueRouter . prototype . getRoutes = function getRoutes ( ) {
3095
+ return this . matcher . getRoutes ( )
3096
+ } ;
3097
+
3098
+ VueRouter . prototype . addRoute = function addRoute ( parentOrRoute , route ) {
3099
+ this . matcher . addRoute ( parentOrRoute , route ) ;
3100
+ if ( this . history . current !== START ) {
3101
+ this . history . transitionTo ( this . history . getCurrentLocation ( ) ) ;
3102
+ }
3103
+ } ;
3104
+
3037
3105
VueRouter . prototype . addRoutes = function addRoutes ( routes ) {
3106
+ if ( process . env . NODE_ENV !== 'production' ) {
3107
+ warn ( false , 'router.addRoutes() is deprecated and has been removed in Vue Router 4. Use router.addRoute() instead.' ) ;
3108
+ }
3038
3109
this . matcher . addRoutes ( routes ) ;
3039
3110
if ( this . history . current !== START ) {
3040
3111
this . history . transitionTo ( this . history . getCurrentLocation ( ) ) ;
@@ -3057,9 +3128,10 @@ function createHref (base, fullPath, mode) {
3057
3128
}
3058
3129
3059
3130
VueRouter . install = install ;
3060
- VueRouter . version = '3.4.9 ' ;
3131
+ VueRouter . version = '3.5.0 ' ;
3061
3132
VueRouter . isNavigationFailure = isNavigationFailure ;
3062
3133
VueRouter . NavigationFailureType = NavigationFailureType ;
3134
+ VueRouter . START_LOCATION = START ;
3063
3135
3064
3136
if ( inBrowser && window . Vue ) {
3065
3137
window . Vue . use ( VueRouter ) ;
0 commit comments