Skip to content

Function: compilePathPattern() ​

ts
function compilePathPattern(pattern): RegExp;

Defined in: packages/next/src/matcher.ts:14

Compiles a Next.js-style path pattern to a RegExp.

  • /admin matches /admin (and /admin/)
  • /users/:id matches one segment
  • /admin/:path* matches /admin, /admin/a, /admin/a/b
  • /admin/:path+ matches /admin/a, /admin/a/b (not /admin)
  • /blog/:slug? matches /blog and /blog/x

Parameters ​

ParameterType
patternstring

Returns ​

RegExp

Released under the MIT License. Inspired by spatie/laravel-permission.