-
-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Filesystem Routing] Avoid samed named files (e.g. 10 filenames +Page.tsx
)
#1322
Comments
+Page.tsx
)
How about: # Route: /about
/pages/about+Page.js
# Route: /products
/pages/products+Page.js
# Route: /product/@id
/pages/product/@id+Page.js Looks weird but it's functional. Upvote and/or comment down below if you want/need this. |
That would definitely work for me (it isn't working right now though according to my testing, right?) |
Correct, this isn't implemented yet. I'm busy with high priorities at the moment, but let's see if I can take a stab at it sometime. There is also #341. @dfrkp Btw. would your company be up for sponsoring? |
Instead of: # Route: /about
/pages/about+Page.js
# Route: /products
/pages/products+Page.js
# Route: /product/@id
/pages/product/@id+Page.js How about: # Route: /about
/pages/+about.page.js
# Route: /products
/pages/+products.page.js
# Route: /product/@id
/pages/product/+@id.page.js Or even just: # Route: /about
/pages/+about.js
# Route: /products
/pages/+products.js
# Route: /product/@id
/pages/product/+@id.js Re my earlier comment: #578 (comment) The arguments for and against Some arguments in favor of the |
@redbar0n Neat ideas, I like them. Although it's a bit unconventional to use the file extension to denote semantics. (That said the whole I think we're going in the right direction 👀 So far I like misusing the file extensions as you propose. Actually, I'm just realizing that Telefunc does that already with its Actually, there is an issue currently when using Vike with Telefunc: # Currently, users define this: (confusing as +Page.telefunc.js isn't a Vike file)
/pages/some-page/+Page.js
/pages/some-page/+Page.telefunc.js
# Or this: (ugly)
/pages/some-page/+Page.js
/pages/some-page/Page.telefunc.js Maybe we can solve that issue as well while we're at it. |
Maybe the trick is to have Vike support both: the
(I understand that |
Those who prefer having page files tucked in their own directly could use /pages/product/@id/+Page.js
/pages/product/@id/+route.js
# We can make Telefunc understand that syntax
/pages/product/@id/+telefunc.js In other words |
@redbar0n WDYT? |
Hey wanted to add my 2 cents here:
To me allowing something like |
@brillout Cool! I'll try to summarize my thoughts and give a suggestion. I realized the part of my suggestions using So how about this? I think the following would be ideal, imho. Prioritising maximum clarity (even without path info available) over terseness, and minimum necessary learning / documentation / variability: # flat
/pages/about.page.js
...
/pages/about.telefunc.js
#folder
## the index
/pages/products/products.config.js
/pages/products/products.layout.js
/pages/products/products.onBeforeRender.js
/pages/products/products.page.js
/pages/products/products.route.js
...
/pages/products/products.telefunc.js
## an item
/pages/product/@productId.config.js
/pages/product/@productId.layout.js
/pages/product/@productId.onBeforeRender.js
/pages/product/@productId.page.js
/pages/product/@productId.route.js
...
/pages/product/@productId.telefunc.js
# similarly, for the generic error page, instead of /pages/_error/+Page.js you could have:
/pages/error.page.js
# similarly for general configs
/pages/pages.config.js # general config
# or, maybe this is better, since people would likely fuzzy search/filter for "vike config" for everything they'd expect Vike to handle
/pages/vike.config.js # general config, named similarly to other frameworks: remix.config.js
# individual custom configs overriding the general one
/pages/admin/admin.config.js
/pages/product/@productId.config.js # like illustrated initially above
This should also obviate the need to rename files when moving them from a flat structure into a folder. I dropped the I dropped having a Vike ideally only has one single syntax: less variation means less opportunity for user error, less documentation needed, less to learn, and easier to go into a new Vike codebase because everything will be familiar. I'd go with the suffix syntax because it is clearer and self-explanatory. If it is really important to show config files at the top of the folder, then people can add Capitalizing Page because it is a component would seem to base the name on semantics. Imho, it's also unintuitive to apply this component convention outside of the JS files - they are just JS files. My conceptualization is that the convention to capitalize component names are something done within the code because of a React / JSX convention. Whereas I consider the file system to belong to the framework, which can have its own conventions irrespective of the chosen view library (esp. when agnostic to it). Uniformity / consistency ("Vike always lowercases the start of file names") also raises fewer questions. By avoiding a one-off convention in the file system, there's less to explain ("Why does Vike capitalize some file names but not others?"), and less to document. The two worlds would meet when you make an: import { AboutPage } from "/pages/about/about.page.js" What do you guys think? |
Or just, like previously suggested (which seemed popular), collate all the Vike stuff into one explicity declared file, so you'd have: #folder
## the index
/pages/products/products.page.js
/pages/products/products.vike.js
...
/pages/products/products.telefunc.js
## an item
/pages/product/@productId.page.js
/pages/product/@productId.vike.js
...
/pages/product/@productId.telefunc.js I think maybe I prefer this, since the amount of files in the file system directory structure often quickly grows out of hand to actually have a nice overview. It also make having a flat folder structure more viable, as the amount of Vike related files would be greatly minimized. |
If you really want to keep the capitalized component name convention, then... Instead of: /pages/products/products.page.js Then the convention could be: /pages/products/ProductsPage.js which would make it clearer that ProductsPage is a component like all the other components in the folder capitalized that way. Then importing would be like: import { ProductsPage } from "/pages/products/ProductsPage.js" |
Not sure if it makes sense, but you could rename the Vike file too, for symmetry / aesthetical reasons. Conceptually you'd think of it as "Vike configures a page": # the index
/pages/products/ProductsPage.js
/pages/products/ProductsPage.vike.js
# item
/pages/product/@ProductIdPage.js
/pages/product/@ProductIdPage.vike.js Even better / clearer perhaps: # the index
/pages/products/Products.js
/pages/products/Products.vike.js
# item
/pages/product/@ProductId.js
/pages/product/@ProductId.vike.js Where by convention the file with the same name as the |
Description
Hi 👋 ! First of all congrats on reaching v1!
I'm unfortunately though holding back on upgrading to the "v1 design" because of the weird way file system routing is behaving now.
To me, the file name of a source code file is much more significant than the folder it is in. I also believe that there are quite a few tools that work better when different files have different names.
So I'm hoping there will be a possibility to retain logical filenames when using filesystem-based routing. If the files need to be in separate folders, fine, but I should be able to name them in whichever way I feel is best.
The text was updated successfully, but these errors were encountered: