File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ The `match` function returns a function for transforming paths into parameters:
68
68
- ** options** _ (optional)_ (See [ parse] ( #parse ) for more options)
69
69
- ** sensitive** Regexp will be case sensitive. (default: ` false ` )
70
70
- ** end** Validate the match reaches the end of the string. (default: ` true ` )
71
+ - ** trailing** Allows optional trailing delimiter to match. (default: ` true ` )
71
72
- ** decode** Function for decoding strings to params, or ` false ` to disable all processing. (default: ` decodeURIComponent ` )
72
73
73
74
``` js
Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ export interface MatchOptions extends PathOptions {
41
41
* Matches the path completely without trailing characters. (default: `true`)
42
42
*/
43
43
end ?: boolean ;
44
+ /**
45
+ * Allows optional trailing delimiter to match. (default: `true`)
46
+ */
47
+ trailing ?: boolean ;
44
48
}
45
49
46
50
export interface CompileOptions extends PathOptions {
@@ -483,12 +487,13 @@ export function $match<P extends ParamData>(
483
487
data : TokenData ,
484
488
options : MatchOptions = { } ,
485
489
) : MatchFunction < P > {
486
- const { decode = decodeURIComponent , end = true } = options ;
490
+ const { decode = decodeURIComponent , end = true , trailing = true } = options ;
487
491
const { tokens, delimiter } = data ;
488
492
const flags = toFlags ( options ) ;
489
493
const [ source , keys ] = toRegExp ( tokens , delimiter ) ;
490
494
491
495
let pattern = `^${ source } ` ;
496
+ if ( trailing ) pattern += `(?:${ escape ( delimiter ) } )?` ;
492
497
pattern += end ? "$" : `(?=${ escape ( delimiter ) } |$)` ;
493
498
const re = new RegExp ( pattern , flags ) ;
494
499
You can’t perform that action at this time.
0 commit comments