๐บ๏ธ Flat Routes #4482
Replies: 26 comments 94 replies
-
@kiliman Has created a package that implements this here: https://github.com/kiliman/remix-flat-routes ๐๐คฉ I haven't had a chance to look deeply at it but will soon. @kiliman can you list here any differences/enhancements/gotchas from my original gist to your implementation before we bring this into Remix proper? |
Beta Was this translation helpful? Give feedback.
-
There's been some discussion about keeping both conventions as official even in v2. Would be curious to hear everybody's thoughts on doing that? I think I'm fine with it, but I'd prefer to just have one convention and continue to let people do whatever they want with |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
Curious here, what is the rationale for using a single underscore for pathless routes instead of |
Beta Was this translation helpful? Give feedback.
-
@kiliman Can you provide an update on your idea of "Hybrid Routes" I'm using your package in my remix app with the I think the idea of hybrid nesting would be very helpful. If I could group routes nested under my pathless layout directory and then by "feature" and have the main parts of those routes flat within it would go a long way to cleaning up the directory names. To be clear - what I'm envisioning is a hybrid of flat-folders where I can optionally next flat-folder routes in a parent directory for organization. The parent directory could be part of the route or a pathless layout |
Beta Was this translation helpful? Give feedback.
-
Based on discussion on Discord, somebody asked if it was possible to combine folders (via hybrid routes) with flat-file format.
Here's my response:
However, one option is to add a character to the folder name to treat this as the route prefix. Perhaps a
This way you can add some folders for grouping, but still use the simpler flat-files convention. |
Beta Was this translation helpful? Give feedback.
-
Not sure what functionality is currently included or is going to be included by v2, but wanted to pose this question: will this scale? A commenter on a question here mentioned they have an app being migrated to Remix that's going to 1k routes. It sounds a bit painful to have 1000+ files in the same place. I may have just missed or misunderstood something, but wanted to make sure that as apps get larger and get into 50-100+ routes or larger that this convention doesn't break down. |
Beta Was this translation helpful? Give feedback.
-
Hey ! I just activated the feature on my project with the future flag v2_routeConvention as suggested in the v1.11.0 changelog. It works like a charm ! Except for one bit, the index routes. Could you tell me if I did something wrong please ? Here is my route tree : And here is the result of <Routes>
<Route file="root.tsx">
<Route file="routes/_anonymous.tsx">
<Route path="login" file="routes/_anonymous.login.tsx" />
<Route path="share/:token" file="routes/_anonymous.share.$token.tsx" />
</Route>
<Route file="routes/_authenticated.tsx">
<Route path="index" file="routes/_authenticated.index.tsx" />
<Route path="trips" file="routes/_authenticated.trips.tsx">
<Route path=":tripKey" file="routes/_authenticated.trips.$tripKey.tsx" />
<Route path="index" file="routes/_authenticated.trips.index.tsx" />
</Route>
</Route>
<Route path="api/locale" file="routes/api.locale.tsx" />
<Route path="dev/null" file="routes/dev.null.ts" />
</Route>
</Routes> The problems are :
|
Beta Was this translation helpful? Give feedback.
-
@ryanflorence @kiliman I think I found a typo in the docs. Before making a PR I would like to know if I understood the implementation correctly. For flat folders to work I need to have an This is what is described in the current docs and the corresponding example. It's also a lot nicer to look at and to reason about IMHO. But maybe I'm missing some implication here? |
Beta Was this translation helpful? Give feedback.
-
Hey folks. Thanks for this improvements. I just implemented the This feeling came out after I rename the files and notice that to see its full name on my editor, I have to increase a lot the side of the navigation: I understand that giving the ability of having nested route folder kinda defeats the purpose of the |
Beta Was this translation helpful? Give feedback.
-
I think there is a finite set of algorithms that is small enough to be considered manageable to have implemented in Remix Core but that would satisfy >90% of cases people are looking for while the remainder could use the escape-hatch to write a custom implementation. What is the best way to get involved in helping with this if possible? |
Beta Was this translation helpful? Give feedback.
-
Is it possible to write a migration script that could automatically convert my Remix repo to route conventions v2 (ie move and rename all the files for me)? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I also think that V2 is step backwards. I think that all those "clever" rules with underscores and "route" files and so on only overcomplicated something that was already solved in the most simple and comprehensive way, and for what purpose - Colocation?? In my opinion "colocation" is a non-issue. For people that wanted to colocate their files with their routes there was already a good mechanism to do so by using the And for me personally I am against colocating with your routes and prefer to keep my route folder only with route files. Makes it easier to find the files and understand the structure of the app/website. And if you wanted to colocate things as module you could always create a parallel folder called "modules" or whatever and colocate your stuff there without polluting your routes. ps. Flat routes are okay, and mixing folders and flat routes is probably the best. But abominations like "route.tsx" in every folder is just code smell. |
Beta Was this translation helpful? Give feedback.
-
I switched my application over to Knowing whether a route has an I started using the local convention of every route folder needs to end with |
Beta Was this translation helpful? Give feedback.
-
I absolutely adore the new v2 routing system. Massive step forward IMO |
Beta Was this translation helpful? Give feedback.
-
Would be nice to have the v1 style as a native option without needing to install separate packages to get functionality back that was taken away. We have around 250 routes in one of our projects that we just migrated to remix, and having them all in the same directory is pretty clunky, and makes it difficult to see what the nesting hierarchy looks like. |
Beta Was this translation helpful? Give feedback.
-
Is there a way to handle two pathless routes in the same position in the new v2 flat routes? I previously had a structure like this:
This meant that the URL With v2, this currently returns an error:
|
Beta Was this translation helpful? Give feedback.
-
Late to the party and this ship has unfortunately probably sailed already, but I personally really dislike this new convention. I think it's a huge step backward in terms of organization. Our app currently has 106 routes and it's a relatively new application with relatively few routes. I really struggle to see how this would work well with a large application with thousands of routes. Coming from a Ruby on Rails background, large production applications often ended up with hundreds of controllers (each controller usually has a couple of routes), and people came up with solutions like namespacing controllers to create some managability in this. A single folder with hundreds of files/folders is simply not very user friendly. One of the things I like/liked about Remix is that it really elegantly solved this problem, because the folder structure follows the user interface, and so as the UI grows in depth of nesting, so does the folder structure. Since I haven't seen anyone else do so, I thought I'd try and argue against the presented arguments:
This is very simple to achieve with even the most minimal of shell scripting:
I grant that a beginner might not know this, but since the remix CLI already has a Personally I've never felt the need to see a list of all of my routes, but YMMV.
The counter arguments are already presented. When consistently using the
If I have 60 routes which are all nested under a certain route, and I want to change the name of the route they are nested under, renaming 60 files is much harder than renaming a single folder. This for me is the biggest argument against the flat structure. The route names are duplicated across dozens of file names at worst. Maintaining consistency is going to be very cumbersome and tedious. Moving files around is easy and fast, both in the CLI and in a file explorer.
We can already do this today by simply using a file with dots in the filename as is supported in the v1 route convention. There is no need to create folders for nesting, even today. Users can then opt in to the benefits of nesting by moving the file into folders after the migration is complete.
This is the most convincing "pro" argument in my opinion. I like the solution proposed by another user in the thread to have a built in convention for files ignored as routes (basically a default for In our application we have extracted all reusable components into |
Beta Was this translation helpful? Give feedback.
-
This idea will look shiny in jokes app but it is creating an absolute mess in routes folder of a corporate app. |
Beta Was this translation helpful? Give feedback.
-
I think @kiliman nailed flat file+folder hybrid routes with
|
Beta Was this translation helpful? Give feedback.
-
This is step in the wrong direction, I believe what is there in v1 is much more superior to this flat structure ๐คฆ |
Beta Was this translation helpful? Give feedback.
-
I think v1 is peak routing. I understand the need to organize helper functions/component next to the route files is needed in specific cases/projects, but to solve that a simple I am forced now to use the |
Beta Was this translation helpful? Give feedback.
-
Ya'll I'm just trying to make my website work and after reading the docs and this thread, I don't think I've ever been more confused in my life. |
Beta Was this translation helpful? Give feedback.
-
how safe it to use @remix-run/v1-route-convention ? |
Beta Was this translation helpful? Give feedback.
-
I started using Remix today. It was so exciting to see the intuitive approach of forms, error boundaries, loaders, etc. But I hit rock bottom when I found out the new v2 file based router patterns. I think v1's was way more extensive and scalable. I don't think I can use v2's pattern on any medium to large scale projects. I'm sorry but I don't think this is the step towards wrong direction. |
Beta Was this translation helpful? Give feedback.
-
Flat Routes File System Conventions
Our current route conventions grew organically and then Jamie hit us with some solid ideas as a catalyst for this. We feel like we have a better idea of what folks need out of the convention especially as React Router apps are being migrated to Remix.
Goals
There are several goals with these changes:
Example
As React Router routes:
Individual explanations:
_auth.forgot-password.tsx
/forgot-password
_auth.tsx
_auth.login.tsx
/login
_auth.tsx
_auth.reset-password.tsx
/reset-password
_auth.tsx
_auth.signup.tsx
/signup
_auth.tsx
_auth.tsx
root.tsx
_landing.about.tsx
/about
_landing.tsx
_landing.index.tsx
/
_landing.tsx
_landing.tsx
root.tsx
app.calendar.$day.tsx
/app/calendar/:day
app.calendar.tsx
app.calendar.index.tsx
/app/calendar
app.calendar.tsx
app.projects.$id.tsx
/app/projects/:id
app.projects.tsx
app.projects.tsx
/app/projects
app.tsx
app.tsx
/app
root.tsx
app_.projects.$id.roadmap.tsx
/app/projects/:id/roadmap
root.tsx
app_.projects.$id.roadmap[.pdf].tsx
/app/projects/:id/roadmap.pdf
Conventions
privacy.jsx
pages.tos.jsx
about.jsx
about.contact.jsx
about.index.jsx
about_.company.jsx
_auth.jsx
_auth.login.jsx
users.$userId.jsx
docs.$.jsx
dashboard.route.jsx
investors/[index].jsx
Justification
Make it easier to see the routes your app has defined - just pop open "routes/" and they are all right there. Since file systems typically sort folders first, when you have dozens of routes it's hard to see which folders have layouts and which don't today. Now all related routes are sorted together.
Decrease refactor/redesign friction - while code editors are pretty good at fixing up imports when you move files around, and Remix has the
"~"
import alias, it's just generally easier to refactor a code base that doesn't have a bunch of nested folders. Remix will no longer force this.Additionally, when redesigning the user interface, it's simpler to adjust the names of files rather than creating/deleting folders and moving routes around to change the way they nest.
Help apps migrate to Remix - Existing apps typically don't have a nested route folder structure like today's conventions. Moving to Remix is arduous because you have to deal with all of the imports.
Colocation - while the example is exclusively files, they are really just "import paths". So you could make a folder for a route instead and the
index
file will be imported, allowing all of a route's modules to live along side each other.For example, these routes:
Could be folders holding their own modules inside:
This is a bit more opinionated, but I think it's ultimately what most developers would prefer. Each route becomes its own "mini app" with all of it's dependencies together. With the routeIgnorePatterns option it's completely unclear which files are routes and which aren't.
Migration Path
You can actually just use remix.config.js right now if somebody writes the code:
Beta Was this translation helpful? Give feedback.
All reactions