github molefrog/wouter v3.2.0
RegExp paths support

latest releases: v3.3.5, v3.3.4, v3.3.3...
5 months ago

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
/[/]([a-z]+)/
// Against "/foo", produces
{ 0: "foo" }

// Route
/[/](?<name>[a-z]+)/
// Against "/foo", produces
{ 0: "foo", name: "foo" }

Don't miss a new wouter release

NewReleases is sending notifications on new releases.