hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.64k stars 65 forks source link

param onMatch() not working #191

Closed jamesmogambi closed 2 years ago

jamesmogambi commented 2 years ago

I tried implementing param matching as specified on docs of next-connect library, but it is not working....? Wanted to implement routes using param matching instead of creating many nested files...?

jamesmogambi commented 2 years ago

``Actually I was defining the route names wrongly, but its working.

Initially I was naming my routes like this: `import nc from "next-connect";

const handler = nc({ attachParams: true, });

handler.get("/user/:id/:", (req, res) => { console.log("dynamic param", req.params); res.json("User created");

});

export default handler;`

But you should name starting with - /api/[path]......: `handler.get("/api/user/:id/:", (req, res) => { console.log("dynamic param", req.params); res.json("User created");

});`