@@ -32,23 +32,22 @@ const UPDATE = (state, url) => {
32
32
export const exec = ( url , route , matches ) => {
33
33
url = url . split ( '/' ) . filter ( Boolean ) ;
34
34
route = ( route || '' ) . split ( '/' ) . filter ( Boolean ) ;
35
- const params = matches . params || ( matches . params = { } ) ;
36
- for ( let i = 0 , val ; i < Math . max ( url . length , route . length ) ; i ++ ) {
35
+ for ( let i = 0 , val , rest ; i < Math . max ( url . length , route . length ) ; i ++ ) {
37
36
let [ , m , param , flag ] = ( route [ i ] || '' ) . match ( / ^ ( : ? ) ( .* ?) ( [ + * ? ] ? ) $ / ) ;
38
37
val = url [ i ] ;
39
38
// segment match:
40
39
if ( ! m && param == val ) continue ;
41
40
// segment mismatch / missing required field:
42
41
if ( ! m || ( ! val && flag != '?' && flag != '*' ) ) return ;
43
- // field match:
44
- params [ param ] = val && decodeURIComponent ( val ) ;
45
- // normal/optional field:
46
- if ( flag >= '?' || flag === '' ) continue ;
42
+ rest = flag == '+' || flag == '*' ;
47
43
// rest (+/*) match:
48
- matches [ param ] = url . slice ( i ) . map ( decodeURIComponent ) . join ( '/' ) ;
49
- break ;
44
+ if ( rest ) val = url . slice ( i ) . map ( decodeURIComponent ) . join ( '/' ) ;
45
+ // normal/optional field:
46
+ else if ( val ) val = decodeURIComponent ( val ) ;
47
+ matches . params [ param ] = val ;
48
+ if ( param != 'ref' && param != 'key' && param != 'path' && param != 'query' && param != 'params' ) matches [ param ] = val ;
49
+ if ( rest ) break ;
50
50
}
51
-
52
51
return matches ;
53
52
} ;
54
53
@@ -108,7 +107,7 @@ export function Router(props) {
108
107
109
108
let p , d , m ;
110
109
toChildArray ( props . children ) . some ( vnode => {
111
- const matches = exec ( path , vnode . props . path , ( m = { path, query } ) ) ;
110
+ const matches = exec ( path , vnode . props . path , ( m = { path, query, params : { } } ) ) ;
112
111
if ( matches ) return ( p = cloneElement ( vnode , m ) ) ;
113
112
if ( vnode . props . default ) d = cloneElement ( vnode , m ) ;
114
113
} ) ;
0 commit comments