-
Notifications
You must be signed in to change notification settings - Fork 64
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
Pattern match not working #110
Comments
Create this file instead doc: https://nextjs.org/docs/api-routes/dynamic-api-routes#optional-catch-all-api-routes |
I've copied the source code locally and assigned assigned @hoangvvo If this is fine I can send a PR. I'm not sure I want to mutate req.query which is assigned by Next.js but it's your call. |
I do not want |
url parsing is done internally by trouter anyways. Trouter.find returns both handlers and params but the params are ignored. I can't see a a way of doing it properly since the matched pattern is not passed to the handlers either so you can't create a middleware. |
I ran against this today. The docs seem to be incorrect in this area. The following example from the docs, does not work. handler.put('/user/:id', (req, res, next) => {
// https://nextjs.org/docs/routing/dynamic-routes
res.end(`User ${req.query.id} updated`);
}); As mentioned above, the id will be available as item in the array A middleware example for how to fix that, would be welcome. But it would also require an update of the docs. |
For now, I'm using For those interested, use diff --git a/node_modules/next-connect/lib/index.js b/node_modules/next-connect/lib/index.js
index 9c5aac6..a4beb92 100755
--- a/node_modules/next-connect/lib/index.js
+++ b/node_modules/next-connect/lib/index.js
@@ -57,10 +57,11 @@ module.exports = ({
nc.handle = function handle(req, res, done) {
const idx = req.url.indexOf("?");
const pathname = idx !== -1 ? req.url.substring(0, idx) : req.url;
- const { handlers } = this.find(
+ const { handlers, params } = this.find(
req.method,
this.baseUrl ? pathname.substring(this.baseUrl.length) : pathname
);
+ req.query = Object.assign({}, req.query, params);
let i = 0;
const len = handlers.length;
const next = (err) => { |
i created file [[...slug]] in api folder and i try to post from postman by this url : localhost:3000/api/users if i remove base ("/users",
Please tell me if it can be fixed soon i wont move to express as spare backend |
maybe its will help someone if it helped you please give me Like to know thats help you 👍 create dynamic file in api folder
|
[[...slug]].js |
It is now possible to use I also add a recipe for quickly migrating from Express that uses the mentioned optional catch-all route feature here |
this does not work for me |
Please create a new issue on this. Thanks! |
this code got error - - error pages/api/Streaming/streaming.tsx (6:21) @ eval
|
I have created index.js file in api folder and using following code. I am getting 404 on both routes.
It works fine if I use dynamic routing by Next.js. Does this optional pattern really works? Because I want to have single file to handle routes like we do in Express.js instead of creating bunch of nested files.
Getting 404 on these routes
The text was updated successfully, but these errors were encountered: