T
TanStack13mo ago
stormy-gold

Should .ts files be ignored by default with file based routing?

In my routes-folders I created a .ts-file (beneath the .tsx-files) . After creating the file, the generator plugin generates the typical createFileRoute in that file (and also includes the routes in routeTree.gen.ts). Obviously this does not work, as a .ts file does not support JSX syntax. When removing the generated code from the .ts-file the code is not generated again, but the "route" is not removed from routeTree.gen.ts (which is inconsistent imho). I didn't found something in the docs nor the source code, so my question is: should .tsfiles be ignored or is it correct that the generator treats them as route files? Personally I'd like to see them ignored, because then I could easily co-locate non-UI files (data loading code, hooks, etc.) with my route files.
5 Replies
rare-sapphire
rare-sapphire13mo ago
Should .ts files be ignored by default with file based routing?
not by default, as you can have routes which don't need JSX syntax (e.g. a layout route that does not have a component defined, or a route that just imports a component from a tsx file)
rare-sapphire
rare-sapphire13mo ago
you can use the routeFileIgnorePattern option to configure router-generator to ignore .ts files: https://tanstack.com/router/v1/docs/framework/react/guide/file-based-routing#options
File-Based Routes | TanStack Router React Docs
Most of the TanStack Router documentation is written for file-based routing. This guide is mostly intended to help you understand in more detail how to configure file-based routing and the technical details behind how it works. Prerequisites
stormy-gold
stormy-goldOP13mo ago
Thanks! That seems to do the trick: "routeFileIgnorePattern": "\\.ts$" btw. is there a known issue, that quoteStyle is not taking into account when generating the code? I set it to. double, but generated quotes are single.
rare-sapphire
rare-sapphire13mo ago
maybe, not sure. we stopped formatting/ or rather stopped adding formatting support for the generated code at some point because generated code should just be left as is by the user, no need to have it match the project formatting.
stormy-gold
stormy-goldOP13mo ago
ok, thanks!

Did you find this page helpful?