Hyphen in express route parameters Hyphen in express route parameters express express

Hyphen in express route parameters


You just can go with regex routes, tried to search something with named capturing groups in js but is not possible so a trick from es6 will come very handy.

router.get(/^\/(\w+)-(\w+)-(\w+)?$/, function(req, res){   const [a, b, c] = req.params;   // a = req.params[0];   // b = req.params[1];   // c = req.params[2];   // implement your logic});


This is the proper way to handle multiple parameters, you will nest each parameter as an additional part of the routeIve included a link to the routing page of express which also goes over thishttps://expressjs.com/en/guide/routing.html

 app.get('/:a/:b/:c', function(req, res) {        var data = {            "data": {                "a": req.params.a,                "b": req.params.b,                "c": req.params.c            }        };         send.json(data);    });