Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated type FileRoutesByFullPath doesn't match runtime type #3780

Open
am-a opened this issue Mar 15, 2025 · 2 comments
Open

Generated type FileRoutesByFullPath doesn't match runtime type #3780

am-a opened this issue Mar 15, 2025 · 2 comments

Comments

@am-a
Copy link

am-a commented Mar 15, 2025

Which project does this relate to?

Router

Describe the bug

Problem

router.routesByPath is defined as RoutesByPath<TRouteTree> which includes trailing '/' for index routes. However this does not match the runtime type which removes trailing slashes.

Description

Given the following structure:

foo/
└── bar/
    ├── index.tsx
    ├── route.tsx
    └── __root.tsx

generates:

export interface FileRoutesByFullPath {
  '/bar': typeof fooBarRouteRouteWithChildren
  '/bar/': typeof fooBarIndexRoute
}

but in:

https://github.com/TanStack/router/blob/4568b38b69b5a649484a8168f4765de97c10f193/packages/react-router/src/router.ts

       if (!childRoute.isRoot && childRoute.path) {
          const trimmedFullPath = trimPathRight(childRoute.fullPath)
          if (
            !(this.routesByPath as any)[trimmedFullPath] ||
            childRoute.fullPath.endsWith('/')
          ) {
            ;(this.routesByPath as any)[trimmedFullPath] = childRoute
          }
        }

we can see that the trimmed path is the key that is used for the object at runtime.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-nychtyxe

Steps to Reproduce the Bug or Issue

  1. Create a router project with an index route matching above structure
  2. Observe that Types does not match runtime types

Expected behavior

The typing for the property should match the runtime type i.e. without slashes

Screenshots or Videos

Image

Platform

All

Additional context

The included link goes to a StackBlitz where you can quickly see the problem in action by comparing the interface and the actual runtime types.

@schiller-manuel
Copy link
Contributor

same as #3005 ?

@am-a
Copy link
Author

am-a commented Mar 15, 2025

same as #3005 ?

Not quite the same, almost the inverse. Probably fixed in the same area though.

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

No branches or pull requests

2 participants