fix: only strip a whole index segment in routePathFromFile - #12
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of solidjs/solid-start#2315 (fixes solidjs/solid-start#2314) to the nested filename convention here.
Current behavior
routePathFromFilestrips a trailingindexwith an unanchored.replace(/index$/, ""), so any route file whose name merely ends withindexloses that suffix:routes/reindex.tsxmaps to/re,routes/myindex.tsxto/my. Directory indexes (reindex/index.tsx→/reindex/) happen to work, which masked it.New behavior
The strip is anchored to a segment boundary (
/(^|\/)index$/), soreindex.tsx→/reindexandblog/reindex.tsx→/blog/reindex. Real index files are unchanged:index→/,blog/index→/blog/,[id]/index→/:id/.The flat convention is not affected:
flatRoutePathFromFiledetects_indexas a whole parsed segment rather than by string suffix.Tests
routePathFromFile: new case coveringreindex,myindex,appendix,blog/reindex,reindex/indexand[id]/index.PageFileSystemRouter: new scan-level case assertingreindex.tsx,blog/index.tsxandblog/myindex.tsxproduce/reindex,/blog/and/blog/myindex.vitest run(105 tests),tsc --noEmitandprettier --checkare clean. Patch changeset included.🤖 Generated with Claude Code