Skip to content

Using route('/') instead of index('/') breaks typegen and type checking #13282

@sam-cook

Description

@sam-cook

I'm using React Router as a...

framework

Reproduction

https://stackblitz.com/edit/github-ckdgdgys

  1. Configure routes.ts file, with route('/', 'path/to/index.tsx') instead of index('path/to/index.tsx') route
  2. Run npm run typecheck
  3. .react-router/types/+register.ts has duplicate "/": {}; entry
  4. Type checking fails due to the duplicate entry
  5. At runtime application continues to work

System Info

System:
    OS: macOS 15.1.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 85.75 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.4.0 - /opt/homebrew/bin/node
    npm: 10.9.2 - /opt/homebrew/bin/npm
    pnpm: 8.9.2 - /opt/homebrew/bin/pnpm
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 134.0.6998.118
    Safari: 18.1.1
  npmPackages:
    @react-router/dev: ^7.3.0 => 7.3.0 
    @react-router/node: ^7.0.0 => 7.3.0 
    @react-router/serve: ^7.3.0 => 7.3.0 
    react-router: ^7.0.0 => 7.3.0 
    vite: ^5.4.14 => 5.4.14

Used Package Manager

npm

Expected Behavior

I see two routes of expected behaviour:

  • The react-router typegen command recognises you are using the route setup for everything instead of index() and does not create duplicate entries in the +register.ts types file.

OR

  • Documentation on the react-router website warns consumers of the requirement to at least have a base index() route
  • The react-router typegen command throws a descriptive error to point the user in the right direction

Option 2 may be easier to code for, since we can just check if there are NO routes with an index: true property.

Actual Behavior

  • react-router typegen command creates two "/": {}; entries in the .react-router/types/+register.ts file
  • Subsequent type checks fail with:
.react-router/types/+register.ts:10:3 - error TS2300: Duplicate identifier '/'.

10   "/": {};
     ~~~

.react-router/types/+register.ts:14:3 - error TS2300: Duplicate identifier '/'.

14   "/": {};
     ~~~


Found 2 errors in the same file, starting at: .react-router/types/+register.ts:10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions