Infinite Parameters In Express Server
I have implemented react router with recursion parameters. something like this i have server with express where i try to handle route /someRoute/:recursiveParameter? router.get('/
Solution 1:
Use wildcards like * in your routes, it also supports Regex, working example:
app.get('/someRoute/*', function(req, res) {
console.log(req.params[0]);
});
// GET /someRoute/v2/this/route
// Output: v2/this/route
Solution 2:
are you looking for something like this?
router.get('/someRoute/.*?', async (req, res, _next) => { whatever here })
Solution 3:
Please use regular expression match for the above scenario. Example:
router.get('/someRoute/*', async (req, res, _next) => { whatever here })
//Correct matches:
/someRoute/a/b/c
/someRoute
/somRoute/something
Also, if you already know the maximum possible number of arguments, you can use "?" which indicates it's optional.
Example:
router.get('/someRoute/:arg1?/:arg2?/:arg3?/:arg4?', async (req, res, _next) => { whatever here })
Refer Express Routing Official Docs: https://expressjs.com/en/guide/routing.html
Post a Comment for "Infinite Parameters In Express Server"