Skip to content

Huge missed opportunity: Routes type safety should be inferred with file-based routing #3571

@newsve

Description

@newsve

Which project does this relate to?

Router

Describe the bug

I file this as bug because this was my expectation when I got into this project, it has been my initial understand about its type safety, I do not think this should be a new feature but the baseline, so please feel free to close this issue if I miss something.

I find the current way and the need to type the route myself in addition to the file naming and location with file-based routing tedious and not DRY:

export const Route = createFileRoute("/")({
  component: Home,
  ...
});

routeTree.gen.ts gets autogenerated all the time anyway and it could also read the file and folder structure and generate typing right from that structure with file-based routing.

I mean, the reason file-based routing got again so popular is that it is dead-simple, it isn't always the best but it is easy, intuitive and gets out of the way. And, it is less work, because you need to name files and folders anyway.

Now we have to do both, naming and decide on the location of a file + declare its route, this is more work while we could just infer the type safety from the file and folder structure.

Also fire-and-forget refactoring is not straight-forward because of the non-DRY nature, you have to manually sync route declaration and file naming and location.

Your Example Website or App

not applicable

Steps to Reproduce the Bug or Issue

not applicable

Expected behavior

Routes type safety should be automatically inferred from the real file and folder structure with file-based routing with the option to manually override typing.

Screenshots or Videos

No response

Platform

not applicable

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions