Next.js and React Router 7 (RR7) have fundamentally different approaches to...


Next.js and React Router 7 (RR7) have fundamentally different approaches to decomposition.

In Next.js, you create many small files per route (Page.tsx, Loading.tsx, etc). Each file has a clear purpose, and must have a certain name.

Result:
Many small files ๐Ÿ‘, but many files in the solution will have the same name ๐Ÿ‘Ž.

In RR7, you create one file per route called a โ€œmoduleโ€. It exports many functions that must have specific names (loader, action, headers, links, handle, meta, etc).

Result:
One clearly named file per route that contains all that routeโ€™s concerns, decomposed into well named functions ๐Ÿ‘, but the file may grow big ๐Ÿ‘Ž.

My take? I prefer RR7โ€™s approach. I prefer unique filenames, and I can decompose the route file if it gets too big.

View original on X