fix(router-generator): give an index/route.tsx index route the path '/' #8672
main fromrefs/pull/8672/head·opened 🎯 Changes#
Fixes #7691.
An index route written as a directory, app/index/route.tsx, is classified as a layout because of the route token. Its trailing slash is then stripped, so the route tree gets path: '' while the generated types in the same file say path: '/':
// routeTree.gen.ts, before
const AppIndexRouteRoute = AppIndexRouteRouteImport.update({
id: '/',
path: '', // <- now '/'
getParentRoute: () => AppRouteRoute,
} as any)
declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/app/': { id: '/app/'; path: '/'; fullPath: '/app/'; ... }
}
}
With an empty path the index route is skipped in routesByPath, so to: '/app' resolves to the layout while matching finds the index. That mismatch is what logs the dev warning from the issue:
Generated path "/app" for route "/app" matched route "/app/" instead.
The fix treats index/route.tsx as the index route it already is in the types, so it generates the same path: '/' as app/index.tsx.
@schiller-manuel noted in the issue that nesting route under index isn't supported. If you'd rather keep it that way, I'm happy to change this to a generator warning for that file layout instead. Today it generates silently and the runtime tree disagrees with its own types.
Tests#
New fixture tests/generator/layout-and-index-directory with the structure from the issue's reproducer (app/route.tsx, app/index/route.tsx, app/test/route.tsx). No existing snapshot changes.
Ran test:unit, test:types and test:eslint for @tanstack/router-generator, and test:unit for @tanstack/router-plugin.
AI disclosure: written with AI assistance.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
- I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
- Bug Fixes
- Fixed route generation for index routes organized in an
index/route.tsxfile. These routes now receive the correct/path relative to their parent, matching generated route types and preventing a development warning. This keeps index routes and their sibling routes correctly represented in the generated route tree.
- Fixed route generation for index routes organized in an
- 1
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Repository: TanStack/router/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6e57ada6-41a7-4da7-b266-beb192e69ac0
📥 Commits
-
Reviewing files that changed from the base of the PR and between 57bd1a92f9839af5bf773c3b36d039569fb1a41e and 23de23a4b2e9eee4c37890b4cd3b37cb3481df67.
📒 Files selected for processing (7)
-
.changeset/generator-index-directory-route.mdpackages/router-generator/src/filesystem/physical/getRouteNodes.tspackages/router-generator/tests/generator/layout-and-index-directory/routeTree.snapshot.tspackages/router-generator/tests/generator/layout-and-index-directory/routes/__root.tsxpackages/router-generator/tests/generator/layout-and-index-directory/routes/app/index/route.tsxpackages/router-generator/tests/generator/layout-and-index-directory/routes/app/route.tsxpackages/router-generator/tests/generator/layout-and-index-directory/routes/app/test/route.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
Walkthrough#
The router generator now classifies an index-directory route as static when it detects an index token on a layout route. The updated fixture records the generated
/approute tree, including its/app/index route and/app/testchild.Changes#
Index directory routes
Layer / File(s) Summary Index-directory route classification
packages/router-generator/src/filesystem/physical/getRouteNodes.tsWhen the index-token branch finds a layout route, getRouteNodesnow sets its route type tostatic.Generated route tree fixture
packages/router-generator/tests/generator/layout-and-index-directory/routes/*,packages/router-generator/tests/generator/layout-and-index-directory/routeTree.snapshot.ts,.changeset/generator-index-directory-route.mdThe fixture defines the root, /app,/app/, and/app/testroutes. The snapshot records their route metadata, types, and tree wiring. The changeset describes generatingpath: '/'for the index route.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: ⚪ Minimal · up to
23de2The reported root-level path concern does not occur, and no issue remains that would prevent merging after normal checks.
Pre-merge checks |
4 | 1-
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
-
Check name Status Explanation Title check The title clearly and concisely describes the main change: assigning path '/' to directory-form index routes in router-generator. Description check The description includes the required Changes, Checklist, and Release Impact sections. It explains the issue, implementation, tests, changeset, and AI assistance. One checklist item remains unchecked,… Linked Issues check Issue #7691requires a directory-form index route under a layout to resolve to the same URL without a false-positive development warning.getRouteNodesnow detects theindexsegment after processi…Out of Scope Changes check The changes stay within issue #7691. The source change fixes directory-form index-route classification. The fixture route files and generated snapshot provide automated coverage for the reported layou…
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files. (1 skipped: 1 unsupported.)
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- 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.
Comment `@coderabbitai help` to get the list of available commands.-
kshanxs(GitHub profile, opens in a new tab) linked this to fix #7691
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 23de23a4b2e9eee4c37890b4cd3b37cb3481df67
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR