Rescale logoNEMO

Route matchers

path-to-regexp matchers for middleware functions

This package uses path-to-regexp package to match the middleware routes path and parse the route params in a same way as Next.js does in config's matcher prop.

Examples

To make it easier to understand, you can check the below examples:

Simple route

Matches /dashboard route and returns no params.

Simple route
/dashboard

Prams

General structure of the params is :paramName where paramName is the name of the param that will be returned in the middleware function.

Single

Matches /dashboard/anything route and returns team param with anything value.

Single
/dashboard/:team

You can also define segments in the middle of URL with is matching /team/anything/dashboard and returns team param with anything value.

Single with suffix
/dashboard/:team/delete

Optional

Matches /dashboard and /dashboard/anything routes and returns team param with anything value if there is value provided in url.

Optional
/dashboard{/:team}
Optional wildcard
/dashboard{/*team}

Wildcard

Matches /dashboard and /dashboard/anything/test routes and returns team param with [anything, test] value if there is value provided in url.

Wildcard
/dashboard/*team

Debugging tool

Path to Regexp debugger

Test your matchers and params parsing

On this page