-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Parameterized routing with filesystem for #91 #147
Conversation
This reverts commit 8ca206d.
Interesting PR! I like the idea very much, although I do have a concern that we're now deviating a bit from the way how nested routing was done in Next (exclusively using folders). I personally still prefer the idea with files like Still, I really like the fact that we now have a working version of parameters in a file system! 👍 |
I agree with @CompuIves, something that uses nested directories feels better. I was working on something similar to this, which had files called
But both of these could be relatively easy to overcome - probably by taking a more advanced approach to changing the resolver than what I did. |
@nias-r I have tested with this PR which supports |
I'd suggest keeping the mapping between files and routes as straightforward and non-magical as possible. @nodegin is there a reason for using This means no i.e. The second form with the
|
@timoxley someone point out that |
There is a nice implementation of directory-style routing, similar to @timoxley 's suggestion, which I've used for APIs in swaggerize-express (see Path Routing), originally written by @tlivings:
Note the use of |
I see a problem in naming files like |
@giacomorebonato nobody stopping you adding context e.g. |
This looks great! But I agree with @CompuIves. I might suggest an alternate of ${} as this fits the js pattern of vars in strings as of es6 |
@mattapperson the purpose of There's nothing wrong with |
@tlivings I dont disagree with you at all, but this project hides hapi, and it's not swagger. It is a server side react server. By it's nature it is JS first. the most JS way to do this in my mind is to use Template literals style. |
No, I get it — I just referenced the other projects because that may also be what people are more familiar with. |
@tlivings I feel ya! Another counter point to my argument though would also be variables in JSX are {param name} so.... |
Does anyone know of an existing system using a filesystem api like this? |
@tlivings @mattapperson template literal syntax is a non-starter due to shell variable expansion. e.g. try creating a file named |
Hah good point @timoxley! |
@dstreet see above comment about swaggerize-express. |
@timoxley Thanks. Not sure how I missed that |
Hi guys, I have updated this PR to use the format as @jharmn suggested:
But I found a bug that causing HMR function to be broken when the link is in |
@nodegin I suggest/request this gets merged and a new ticket get created for the known HMR bug. This is a major feature that allows next.js to be used in much larger apps. The HMR bug is annoying but not critical. This feature however is critical to many apps (like mine, selfishly) |
@mattapperson Only collaborators can merge this PR |
Using this branch, I created a "pages/index.js". Requests to "/" are routed to that page. I then created an additional "pages/{id}.js". Now requests to "/" are being routed to "pages/{id}.js" even though pages/index.js is a more specific match. Also, requests for "/foo/bar" are also getting routed to "pages/{id}.js" - This is not how other frameworks handle this type of routing. I would expect "/foo" to get routed to "pages/{id}.js", but "/foo/bar" to 404. |
Also. I created "pages/foo/index.js", and now requests for "/foo/" get routed there, but "/foo" get routed to "pages/{id}.js". |
I think that it is not good to use parameter names for file names and paths. Because it causes you to do ls to find _xxx.js. For example, in a directory containing 100,000 files, performance will be problematic. I think that it is better to statically determine the name of the file to search from the request URL. I have an idea.
Developers can freely determine parameter names and path names.
And catch all parameter.
|
My performance problem (many files in directory) is only in development. (with hot loading) |
@nodegin bump, looks like there's some conflicts to fix |
@timoxley I believe this PR is out of date and Next.js probably would go for another better solution such as a |
@nodegin can you provide details on the HMR bug? |
There are also the bugs that I mentioned. I don't think this is just a case of fix the conflicts and then release, IMHO the numerous bugs need fixing first. |
The conversation was moved to #291 (if I'm not wrong - just a newbie here) |
Hello, here is a proof of concept pull request for issue #91 that achieves parameterized routing using only filesystem structure.
Filesystem
Code
Result