Skip to content

Docs: middleware matcher config sample should be explicit about root route #62078

@dmudro

Description

@dmudro

What is the improvement or update you wish to see?

The config sample on middleware docs page states

To match all request paths except for the ones starting with:

export const config = {
  matcher: ['/((?!api|_next/static|favicon.ico).*)'],
};

In my experience, root route /, i. e. homepage is not caught by this regex which I think is expected given the negative look ahead with .*.

My workaround is adding a separate matcher:

export const config = {
  matcher: [
    '/((?!api|_next/static|favicon.ico).*)',
    '/', // explicit matcher for root route
  ],
};

The docs should be more clear about root route excluded from middleware execution.

Is there any context that might help us understand?

The docs should be more clear about root route excluded from middleware execution.

It's easy to miss it when using the current config sample.

Does the docs page already exist? Please link to it.

https://vercel.com/docs/functions/edge-middleware/middleware-api#match-based-on-a-negative-lookahead

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Documentation.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions