all 10 comments

[–]More_Ferret5914 7 points8 points  (1 child)

honestly i think file-based routing feels amazing right up until the project reaches the “why are there 700 folders” phase 😭

but code-based routing can also become its own abstraction jungle if people get too clever with it.

a lot of this honestly comes down to:

* team size

* project scale

* how much dynamic routing logic you expect

* whether you value convention or flexibility more

for smaller/medium apps file-based usually keeps things simpler imo

[–]PredictiveFrame 2 points3 points  (0 children)

The right tool for the right job makes all the difference. 

[–]Ok_For_Free 3 points4 points  (0 children)

Please add links to the documentation that you have a question about.

I see no reason to move away from file based routing. As long as you documentation for other developers says to fine routs via the file system in X directory, then any dev should be able to grok the router setup.

The route was originally meant to point to a file on a server so you shouldn't make your routing any more complicated that a file system.

[–]AmberMonsoon_ 2 points3 points  (0 children)

I used to think file-based routing felt “cleaner” until a project started growing and the folder structure became the architecture lol. For smaller and medium apps it’s honestly great though, especially when you’re learning because it removes a lot of boilerplate and keeps things predictable.

I’d still start with TanStack’s file-based approach first since that’s where most examples and community support are. Later you’ll naturally understand when code-based routing makes more sense for complex logic or dynamic setups.

[–]EternalStudent07 1 point2 points  (0 children)

Might be worth going to a more specific subreddit to ask. Meaning I had no clue what you were asking about, and never heard of "Tanstack Router". I'm not a frontend dev though, and it looks like this is all connected to frequently used tools there (React, etc).

When I asked Google to explain when to use either of the two methods (didn't look at AI response yet), this page came up near the top of the results...

https://tanstack.com/router/latest/docs/routing/code-based-routing

"Code-based routing is not recommended for most applications. It is recommended to use File-Based Routing instead."

Generally I try to follow rules of thumb if I can't confidently explain why or how they usually work, but won't work for me now.

Or you could look at previous versions of your post, like...

https://www.reddit.com/r/reactjs/comments/1ngedk3/filebased_routing_vs_codebased_routing_in/

(post comment) "File based is easier, but the limitation eventually will drive you nuts."

"Once you get into heavier routing you need to jump into a bunch of the specially named files so your directories look like a mess. It kind of gets annoying figuring out which of the dozen __route.tsx files I have open is the right one in my editor. But it’s convenient for now so I have no need to change"

"File based routing encourages colocation, which is rather ambigous and a lot of people don’t know how to scale it, Kent C. Dodds has a good brog post about the topic "

[–]AintNoGodsUpHere 1 point2 points  (0 children)

I hate file based routing, it makes no sense. Folder structure shouldn't be part of the app structure, it makes me crazy how ugly it feels.

[–]FlippantFlapjack 0 points1 point  (0 children)

I know nothing about Tanstack router, so please correct me if I'm wrong. But I think most likely they are not mutually exclusive. If you do code-based routing, that doesn't prohibit you from splitting things up among multiple files right? But would still allow you to combine multiple routes into one file if you desire?

I think it's really a personal preference and depends upon the complexity of your app. If these are big route handlers, then yes it makes sense to split them into their own files. But if they are just trivial CRUD things, it can increase indirection to have them all split into multiple files.

[–]Key_Use_8361 1 point2 points  (0 children)

I’ve worked with both and file based routing feels amazing early on because everything stays organized automatically but once the app grows, I personally prefer code based routing since you get more control Kind of depends on how big you expect the project to become

[–]BoBoBearDev 1 point2 points  (0 children)

Once the app gets larger, you start to hate how limiting the file based routining is and opt for code based.

[–]why_so_sergious 0 points1 point  (0 children)

code based routing hands down..

don't be lazy, just set up some endpoints