Skip to content

fix: only strip a whole index segment in routePathFromFile - #12

Merged
birkskyum merged 1 commit into
mainfrom
fix-index-suffix-segment
Sep 10, 2026
Merged

fix: only strip a whole index segment in routePathFromFile#12
birkskyum merged 1 commit into
mainfrom
fix-index-suffix-segment

Conversation

@brenelz

@brenelz brenelz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Port of solidjs/solid-start#2315 (fixes solidjs/solid-start#2314) to the nested filename convention here.

Current behavior

routePathFromFile strips a trailing index with an unanchored .replace(/index$/, ""), so any route file whose name merely ends with index loses that suffix: routes/reindex.tsx maps to /re, routes/myindex.tsx to /my. Directory indexes (reindex/index.tsx/reindex/) happen to work, which masked it.

New behavior

The strip is anchored to a segment boundary (/(^|\/)index$/), so reindex.tsx/reindex and blog/reindex.tsx/blog/reindex. Real index files are unchanged: index/, blog/index/blog/, [id]/index/:id/.

The flat convention is not affected: flatRoutePathFromFile detects _index as a whole parsed segment rather than by string suffix.

Tests

  • routePathFromFile: new case covering reindex, myindex, appendix, blog/reindex, reindex/index and [id]/index.
  • PageFileSystemRouter: new scan-level case asserting reindex.tsx, blog/index.tsx and blog/myindex.tsx produce /reindex, /blog/ and /blog/myindex.
  • vitest run (105 tests), tsc --noEmit and prettier --check are clean. Patch changeset included.

🤖 Generated with Claude Code

Route files whose names merely end in "index" (e.g. `routes/reindex.tsx`)
were mapped to `/re` instead of `/reindex` because the nested convention
used an unanchored `/index$/` replace. Anchor the strip to a segment
boundary so only a real `index` file maps to its directory's path.

Same fix as solidjs/solid-start#2315 for solidjs/solid-start#2314.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@birkskyum
birkskyum merged commit fa2ddc7 into main Sep 10, 2026
3 checks passed
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.

fs router strips any trailing "index" substring, mis-routing pages like reindex.tsx to /re

2 participants