Next.js Discord

Discord Forum

How next js middleware matcher works?

Unanswered
Iridescent shark posted this in #help-forum
Open in Discord
Iridescent sharkOP
I would like to make a custom middleware for api routes, but I want to use config similar to that is used in next js middleware? Does it use regex to define if /posts/update/id1234 - is route it need to apply middleware to? And how it understands that id1234 - third param in url is id of post and not a regular path element /posts/update/details/id1234?
export const config = {
  matcher: [
    '/api/:path*',
    '/posts/create',
    '/posts/update/:path*'
  ]
}

0 Replies