This is `canary` version of documentation. It's still under construction and review.
ZANREAL 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.

  /dashboard
  /
  /home
  /dashboard [PASS] 
  /settings

Grouped routes

Matches /v1 and /v2 prefixed routes.

  /(v1|v2)/:path*
  /
  /home
  /v1/anything [PASS] 
  /v2/anything [PASS] 
  /settings

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.

  /dashboard/:team
  /
  /home
  /dashboard
  /dashboard/team1 [PASS] 
  /dashboard/team2 [PASS] 
  /settings

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

  /dashboard/:team/delete
  /
  /home
  /dashboard
  /dashboard/team1
  /dashboard/team2/delete [PASS] 
  /settings

Optional

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

  /team/:slug?
  /
  /home
  /dashboard
  /team                [PASS] 
  /team/team1          [PASS] 
  /team/team2/settings
  /settings

Optional Wildcard

Zero or more params

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

  /team/:slug*
  /
  /home
  /dashboard
  /team/team1          [PASS] 
  /team/team2/settings [PASS] 
  /settings

Required Wildcard

One or more params

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

  /team/:slug+
  /
  /home
  /dashboard
  /team/team1          [PASS] 
  /team/team2/settings [PASS] 
  /settings