1
1
/* @flow */
2
2
3
3
import type VueRouter from './index'
4
+ import { resolvePath } from './util/path'
4
5
import { assert , warn } from './util/warn'
5
6
import { createRoute } from './util/route'
7
+ import { fillParams } from './util/params'
6
8
import { createRouteMap } from './create-route-map'
7
- import { resolvePath } from './util/path'
8
9
import { normalizeLocation } from './util/location'
9
- import { getRouteRegex , fillParams } from './util/params'
10
10
11
11
export type Matcher = {
12
12
match : ( raw : RawLocation , current ? : Route , redirectedFrom ? : Location ) => Route ;
@@ -36,7 +36,7 @@ export function createMatcher (
36
36
if ( process . env . NODE_ENV !== 'production' ) {
37
37
warn ( record , `Route with name '${ name } ' does not exist` )
38
38
}
39
- const paramNames = getRouteRegex ( record . path ) . keys
39
+ const paramNames = record . regex . keys
40
40
. filter ( key => ! key . optional )
41
41
. map ( key => key . name )
42
42
@@ -60,8 +60,9 @@ export function createMatcher (
60
60
location . params = { }
61
61
for ( let i = 0 ; i < pathList . length ; i ++ ) {
62
62
const path = pathList [ i ]
63
- if ( matchRoute ( path , location . params , location . path ) ) {
64
- return _createRoute ( pathMap [ path ] , location , redirectedFrom )
63
+ const record = pathMap [ path ]
64
+ if ( matchRoute ( record . regex , location . path , location . params ) ) {
65
+ return _createRoute ( record , location , redirectedFrom )
65
66
}
66
67
}
67
68
}
@@ -171,12 +172,11 @@ export function createMatcher (
171
172
}
172
173
173
174
function matchRoute (
175
+ regex : RouteRegExp ,
174
176
path : string ,
175
- params : Object ,
176
- pathname : string
177
+ params : Object
177
178
) : boolean {
178
- const { regexp , keys } = getRouteRegex ( path )
179
- const m = pathname . match ( regexp )
179
+ const m = path . match ( regex )
180
180
181
181
if ( ! m ) {
182
182
return false
@@ -185,9 +185,11 @@ function matchRoute (
185
185
}
186
186
187
187
for ( let i = 1 , len = m . length ; i < len ; ++ i ) {
188
- const key = keys [ i - 1 ]
188
+ const key = regex . keys [ i - 1 ]
189
189
const val = typeof m [ i ] === 'string' ? decodeURIComponent ( m [ i ] ) : m [ i ]
190
- if ( key ) params [ key . name ] = val
190
+ if ( key ) {
191
+ params [ key . name ] = val
192
+ }
191
193
}
192
194
193
195
return true
0 commit comments