Next.js Discord

Discord Forum

Middleware config matcher settings

Unanswered
Silver posted this in #help-forum
Open in Discord
Avatar
SilverOP
If I use a configuration like this in middleware.ts:
const pathAuth: readonly string[] = ["/dashboard/(.*)", "/private/(.*)"];
const pathLocale: readonly string[] = ["/article/(.*)", "/article"];

export const config = {
  matcher: [...pathAuth, ...pathLocale],
};

A warning occurs:
⚠ ./middleware.ts
Unable to parse config export in source file
The exported configuration object in a source file need to have a very specific format from which some properties can be statically parsed at compiled-time.

But if I change it to:
const pathAuth: string[] = ["/dashboard/(.*)", "/private/(.*)"];
const pathLocale: string[] = ["/article/(.*)", "/article"];

// export const config = {
//   matcher: [...pathAuth, ...pathLocale],
// };

export const config = {
  matcher: ["/dashboard/(.*)", "/private/(.*)", "/article/(.*)", "/article"],
};

The problem is gone.

But I want to group related paths, how should I accomplish this?


I searched the issues for an answer, but [not much](https://github.com/vercel/next.js/issues/63896) was found.

0 Replies