Reputation: 1505
Below is my code snippet. When I make an HTTP request to http://localhost:3000/address
it works, but when I make a request to http://localhost:3000/address/3
it doesn't work. What I am doing wrong?
router.get('/:route(address(es)?|documents?)/:id?', async (req, res) => {
const {route, id} = req.params;
console.log(route, id)
});
Upvotes: 0
Views: 30
Reputation: 2145
Change the brackets in address(es)
to square ones in order to avoid the 404 error, so that the route looks like this: '/:route(address[es]?|documents?)/:id?'
Upvotes: 1