快递服务器中的无限参数 [英] Infinite parameters in express server
问题描述
I have implemented react router with recursion parameters. something like this
我有一个具有Express的服务器,我尝试在其中处理路由/someRoute/:recursiveParameter?
i have server with express where i try to handle route /someRoute/:recursiveParameter?
router.get('/someRoute/:recursiveParameter?', async (req, res, _next) => { whatever here })
但是我无法使用更多参数捕获路线,例如.
but i am not able to catch route with more parameters eg.
localhost://someRoute/param1/param2
我找不到任何解决方案.另外,我无法编写诸如someRoute/:param1/:param2之类的路由,因为我不知道会有多少个参数.
I can't find any solution for this. Also I can't write route like someRoute/:param1/:param2 because I don't know how many parameters there will be.
我该如何解决带有Express路由的未知动态参数的问题?
How can I solve this with number of unknown dynamic parameters in a route with express? thx
推荐答案
在您的路由中使用*之类的通配符,它还支持Regex,有效示例:
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
这篇关于快递服务器中的无限参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!