11/* @flow */
22
33import type VueRouter from './index'
4+ import { resolvePath } from './util/path'
45import { assert , warn } from './util/warn'
56import { createRoute } from './util/route'
7+ import { fillParams } from './util/params'
68import { createRouteMap } from './create-route-map'
7- import { resolvePath } from './util/path'
89import { normalizeLocation } from './util/location'
9- import { getRouteRegex , fillParams } from './util/params'
1010
1111export type Matcher = {
1212 match : ( raw : RawLocation , current ? : Route , redirectedFrom ? : Location ) => Route ;
@@ -36,7 +36,7 @@ export function createMatcher (
3636 if ( process . env . NODE_ENV !== 'production' ) {
3737 warn ( record , `Route with name '${ name } ' does not exist` )
3838 }
39- const paramNames = getRouteRegex ( record . path ) . keys
39+ const paramNames = record . regex . keys
4040 . filter ( key => ! key . optional )
4141 . map ( key => key . name )
4242
@@ -60,8 +60,9 @@ export function createMatcher (
6060 location . params = { }
6161 for ( let i = 0 ; i < pathList . length ; i ++ ) {
6262 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 )
6566 }
6667 }
6768 }
@@ -171,12 +172,11 @@ export function createMatcher (
171172}
172173
173174function matchRoute (
175+ regex : RouteRegExp ,
174176 path : string ,
175- params : Object ,
176- pathname : string
177+ params : Object
177178) : boolean {
178- const { regexp , keys } = getRouteRegex ( path )
179- const m = pathname . match ( regexp )
179+ const m = path . match ( regex )
180180
181181 if ( ! m ) {
182182 return false
@@ -185,9 +185,11 @@ function matchRoute (
185185 }
186186
187187 for ( let i = 1 , len = m . length ; i < len ; ++ i ) {
188- const key = keys [ i - 1 ]
188+ const key = regex . keys [ i - 1 ]
189189 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+ }
191193 }
192194
193195 return true
0 commit comments