Skip to content

RegExp paths support

Choose a tag to compare
@molefrog molefrog released this 30 May 09:11
· 5 commits to v3 since this release

Thanks to @JonahPlusPlus, you can now use regular expressions to define custom route patterns. This can be useful, for example, when you need additional validation of a route parameter. See #449

// this will only match numeric IDs, e.g. "/101", but not "/abc" 
<Route path={/^[/](?<id>\d+)$/}>Hello</Route>

The example above uses named capturing groups to have id available as a route parameter. However, you can also use regular groups and access these parameters via numeric indices:

// Route
// Against "/foo", produces
{ 0: "foo" }

// Route
// Against "/foo", produces
{ 0: "foo", name: "foo" }