简体   繁体   中英

Unable to get param in express JS

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)
});

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?'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM