Skip to content
Source
Sign inSign up
TanStack/router

fix(router-generator): give an index/route.tsx index route the path '/' #8672

Openkshanxs(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8672/headopened

🎯 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.tsx file. 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.
    1. 🦋 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
      NameType
      @tanstack/router-generatorPatch
      @tanstack/router-cliPatch
      @tanstack/router-pluginPatch
      @tanstack/start-plugin-corePatch
      @tanstack/router-vite-pluginPatch
      @tanstack/react-start-rscPatch
      @tanstack/react-startPatch
      @tanstack/solid-startPatch
      @tanstack/vue-startPatch

      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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.md
      • packages/router-generator/src/filesystem/physical/getRouteNodes.ts
      • packages/router-generator/tests/generator/layout-and-index-directory/routeTree.snapshot.ts
      • packages/router-generator/tests/generator/layout-and-index-directory/routes/__root.tsx
      • packages/router-generator/tests/generator/layout-and-index-directory/routes/app/index/route.tsx
      • packages/router-generator/tests/generator/layout-and-index-directory/routes/app/route.tsx
      • packages/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 /app route tree, including its /app/ index route and /app/test child.

      Changes

      Index directory routes

      Layer / File(s)Summary
      Index-directory route classification
      packages/router-generator/src/filesystem/physical/getRouteNodes.ts
      When the index-token branch finds a layout route, getRouteNodes now sets its route type to static.
      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.md
      The fixture defines the root, /app, /app/, and /app/test routes. The snapshot records their route metadata, types, and tree wiring. The changeset describes generating path: '/' 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 23de2

      The reported root-level path concern does not occur, and no issue remains that would prevent merging after normal checks.

      Pre-merge checks | Passed 4 | Failed 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring 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 nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: assigning path '/' to directory-form index routes in router-generator.
      Description checkPassedThe 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 checkPassedIssue #7691 requires a directory-form index route under a layout to resolve to the same URL without a false-positive development warning. getRouteNodes now detects the index segment after processi…
      Out of Scope Changes checkPassedThe 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.

      ❤️ Share

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

Sign in to join this conversation.