vercel/next.js

Middleware matcher does not catch root path if base path is set

andreynovikov opened this issue · 0 comments

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/boring-cookies-go8s7s

To Reproduce

  1. Start application
  2. Open root url (/test) - nothing will happen (but it should redirect)

Current vs. Expected behavior

Commonly used matcher:

export const config = {
    matcher: [
        '/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)'
    ]
}

does not catch root path if base path is set in next config.

If I add sole / it matches:

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

If I remove base path from config the first example matches root path.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Debian 6.1.115-1 (2024-11-01)
  Available memory (MB): 31945
  Available CPU cores: 8
Binaries:
  Node: 21.7.1
  npm: 10.8.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.4 // There is a newer version (15.1.0) available, upgrade recommended! 
  eslint-config-next: 15.0.4
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.6.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Other (Deployed)

Additional context

No response