Skip to content

fix(routing): match base path for named catch-all routes - #4812

Merged
pi0 merged 1 commit into
mainfrom
fix/named-catchall-base
Oct 17, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/named-catchall-base

Conversation

@pi0x

@pi0x pi0x commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #4808 (see also #1242)

File routes like routes/test/[...path].ts were scanned as /test/**:path. In rou3, **:name needs at least one segment, so /test and /test/ returned 404, while the unnamed routes/test/[...].ts (/test/**) matched them.

Named catch-alls are now scanned as /test/:path(.*), which matches zero or more segments:

  • /test gives no path param (undefined)
  • /test/ gives params.path === ""
  • /test/a/b gives params.path === "a/b" (same as before)

A sibling routes/test/index.ts still wins for /test. The compiled router is as fast as or a bit faster than before with this pattern.

Code that read the old **:name form now handles the new one too:

  • Vercel function names stay [...name]
  • OpenAPI paths stay {name}
  • route chunk names are now [...name] (they used to come out as [...][name])
  • the Vite dev check that treats a root-level routes/[...slug].ts as a catch-all

Behavior change:

  • Requests to the base path of a named catch-all (e.g. /test) now hit that handler instead of returning 404, so a handler that assumes the param is always set will now see undefined or "".
  • Nested catch-alls now handle their own base path. With routes/[...slug].ts and routes/docs/[...a].ts, /docs used to go to the root catch-all with slug="docs". It now goes to docs/[...a].ts with a undefined. In the same way, /docs/guide moves from docs/[...a].ts to docs/guide/[...b].ts when both exist.
  • A root routes/[...slug].ts now also matches / with slug="". With a renderer, / now reaches that catch-all first instead of returning 404 from it.
  • The http.route trace attribute (and the span name) for these routes changes from /x/**:slug to /x/:slug(.*).
  • [...slug].json.ts and v-[...slug].ts used to fail the build, because rou3 rejected **:slug.json and v-**:slug. They now build as :slug(.*).json and v-:slug(.*).

Tests: I added fixture routes api/catch-all/[...slug].ts and api/catch-all-index/{index,[...slug]}.ts with assertions in test/tests.ts (these fail on main with a 404), plus an OpenAPI check and unit cases for the Vercel dest and the chunk names. Vercel snapshots are updated: the src regexes now also match the base path.

🤖 Generated with AI assistant

Scan `[...name]` as `:name(.*)` instead of `**:name`, which in rou3 requires at least one segment.
@vercel

vercel Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Oct 17, 2026 12:41pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0e714910-9aec-4b51-8aae-b382fa444609
📥 Commits

Reviewing files that changed from the base of the PR and between 5e61db0 and fb32d04.

📒 Files selected for processing: 15
  • docs/1.docs/5.routing.md
  • src/build/chunks.ts
  • src/build/vite/dev.ts
  • src/presets/vercel/utils.ts
  • src/runtime/internal/routes/openapi.ts
  • src/scan.ts
  • test/fixture/server/routes/api/catch-all-index/[...slug].ts
  • test/fixture/server/routes/api/catch-all-index/index.ts
  • test/fixture/server/routes/api/catch-all/[...slug].ts
  • test/presets/nitro-dev.test.ts
  • test/presets/vercel.test.ts
  • test/tests.ts
  • test/unit/chunks.test.ts
  • test/unit/vercel-observability-routes.test.ts
  • test/vite/root-wildcard.test.ts
+-----------------------------------+
| Mission: Impossible - Rogue Code. |
+-----------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4812

commit: fb32d04

@pi0
pi0 merged commit 5384117 into main Oct 17, 2026
14 of 15 checks passed
@pi0
pi0 deleted the fix/named-catchall-base branch October 17, 2026 12:47

This branch was successfully deployed

1 active deployment
Preview — fb32d041 Deployed Oct 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

named catch-all routes ([...name]) don't match the base path

2 participants