1
1
/**
2
- * vue-router v2.0.2
2
+ * vue-router v2.0.3
3
3
* (c) 2016 Evan You
4
4
* @license MIT
5
5
*/
@@ -1035,6 +1035,8 @@ function normalizePath (path, parent) {
1035
1035
1036
1036
var regexpCache = Object . create ( null )
1037
1037
1038
+ var regexpParamsCache = Object . create ( null )
1039
+
1038
1040
var regexpCompileCache = Object . create ( null )
1039
1041
1040
1042
function createMatcher ( routes ) {
@@ -1052,14 +1054,15 @@ function createMatcher (routes) {
1052
1054
1053
1055
if ( name ) {
1054
1056
var record = nameMap [ name ]
1057
+ var paramNames = getParams ( record . path )
1055
1058
1056
1059
if ( typeof location . params !== 'object' ) {
1057
1060
location . params = { }
1058
1061
}
1059
1062
1060
1063
if ( currentRoute && typeof currentRoute . params === 'object' ) {
1061
1064
for ( var key in currentRoute . params ) {
1062
- if ( ! ( key in location . params ) ) {
1065
+ if ( ! ( key in location . params ) && paramNames . indexOf ( key ) > - 1 ) {
1063
1066
location . params [ key ] = currentRoute . params [ key ]
1064
1067
}
1065
1068
}
@@ -1174,13 +1177,10 @@ function createMatcher (routes) {
1174
1177
return match
1175
1178
}
1176
1179
1177
- function matchRoute (
1178
- path ,
1179
- params ,
1180
- pathname
1181
- ) {
1182
- var keys , regexp
1180
+ function getRouteRegex ( path ) {
1183
1181
var hit = regexpCache [ path ]
1182
+ var keys , regexp
1183
+
1184
1184
if ( hit ) {
1185
1185
keys = hit . keys
1186
1186
regexp = hit . regexp
@@ -1189,6 +1189,18 @@ function matchRoute (
1189
1189
regexp = index ( path , keys )
1190
1190
regexpCache [ path ] = { keys : keys , regexp : regexp }
1191
1191
}
1192
+
1193
+ return { keys : keys , regexp : regexp }
1194
+ }
1195
+
1196
+ function matchRoute (
1197
+ path ,
1198
+ params ,
1199
+ pathname
1200
+ ) {
1201
+ var ref = getRouteRegex ( path ) ;
1202
+ var regexp = ref . regexp ;
1203
+ var keys = ref . keys ;
1192
1204
var m = pathname . match ( regexp )
1193
1205
1194
1206
if ( ! m ) {
@@ -1222,6 +1234,11 @@ function fillParams (
1222
1234
}
1223
1235
}
1224
1236
1237
+ function getParams ( path ) {
1238
+ return regexpParamsCache [ path ] ||
1239
+ ( regexpParamsCache [ path ] = getRouteRegex ( path ) . keys . map ( function ( key ) { return key . name ; } ) )
1240
+ }
1241
+
1225
1242
function resolveRecordPath ( path , record ) {
1226
1243
return resolvePath ( path , record . parent ? record . parent . path : '/' , true )
1227
1244
}
0 commit comments