generouted icon indicating copy to clipboard operation
generouted copied to clipboard

Colocating non page components

Open zebapy opened this issue 2 years ago • 3 comments

One of my gripes with file based routes is you usually cannot co-locate components that belong to a page in the same folder. Is this possible with this package?

Something like:

  • pages/contact/index.ts
  • pages/contact/_components/form.tsx

zebapy avatar Sep 09 '22 11:09 zebapy

It sounds like a good default to be added in generouted, thank you for bringing that up. Also seems pretty straight forward to filter out private paths, will try to add that in an upcoming release.

If I understand correctly, any page path contains directory or route starts with an underscore will be ignored:

  • /pages/_private.tsx
  • /pages/contact/_components/button.tsx
  • /pages/contact/_components/tabs/index.tsx

oedotme avatar Sep 13 '22 08:09 oedotme

I'm not sure if the underscore prefix is the right call but it seems somewhat inline with other patterns I've seen, which is why I suggested it. Thanks for fast response and interest

zebapy avatar Sep 14 '22 01:09 zebapy

➕ for this, I think the underscore prefix is a good default here and I would love the ability to co-locate page-related components in generouted 🤓

davemo avatar Oct 19 '22 13:10 davemo

I'm not sure if you've seen it, Next.js 13 is now allowing pages to be collocated with components. They are doing it in a way that is retro-compatible with the existing pages/ paradigm in order to facilitate gradual adoption. It's pretty cool, check it out: https://nextjs.org/blog/next-13#app-directory-beta

If you want to stay close to what Next is doing, an App/ folder would be a very worthwhile feature.

image (image taken from the page linked above)

user72356 avatar Oct 27 '22 21:10 user72356

IMHO the separation between routes and components makes it more clear. I like the idea to support co-locating page related components as it might be handy and expected but it's not my personal preference.

If you want to stay close to what Next is doing, an App/ folder would be a very worthwhile feature.

Next.js new router is very promising, but I see it offers much more than the routing conventions.

oedotme avatar Oct 29 '22 21:10 oedotme

This is a related opinion/take 😄: https://mobile.twitter.com/delba_oliveira/status/1586666502039691264

oedotme avatar Oct 30 '22 10:10 oedotme

Quick update, supporting co-locating non-pages files inside pages/ directory with _ prefix was added here https://github.com/oedotme/generouted/commit/87ed45417f0882d2fae058401c4a65d13fc9d9d2.

Another related update, _layout.tsx is also now supported (similar to Expo router and Next.js new router) https://github.com/oedotme/generouted/issues/13

Will close this issue with a new version release, after some required docs updates.

oedotme avatar Oct 30 '22 22:10 oedotme