express-enrouten icon indicating copy to clipboard operation
express-enrouten copied to clipboard

Route name query

Open tapankumar opened this issue 7 years ago • 1 comments

I have added a named route and would like to know how will I get the same via request object.

I want to know the name of the route which got matched.

Example:

router({ path: '/user/:id', name: 'user-info' }) .get(function (req, res) { //Here I am looking for route name which got matched. res.send(req.route.name); });

tapankumar avatar May 25 '17 15:05 tapankumar

@tapankumar You can get it using req.baseUrl. We still have access to the same express's Request object as we used to while writing using plain express.

dsaraswati avatar Jun 09 '17 11:06 dsaraswati