Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
expressjs:即使未知,如何捕获所有路由参数?_Express_Routes - Fatal编程技术网

expressjs:即使未知,如何捕获所有路由参数?

expressjs:即使未知,如何捕获所有路由参数?,express,routes,Express,Routes,假设我有这条路线 this.app.use('/app/fileasset/ui.html/:view*?', function(req,res) {}); 如果我有此url:/app/fileasset/ui.html/test/view 然后我可以在req.params==>req.params[0](根url,“test”)和req.params.view(“view”)中捕获它们 问题是:如何捕获未知数量的参数 例如:/app/fileasset/ui.html/test/view/s

假设我有这条路线

this.app.use('/app/fileasset/ui.html/:view*?', function(req,res) {});
如果我有此url:/app/fileasset/ui.html/test/view

然后我可以在req.params==>req.params[0](根url,“test”)和req.params.view(“view”)中捕获它们

问题是:如何捕获未知数量的参数

例如:/app/fileasset/ui.html/test/view/subview/wtv

如何在req.params中获取“subview”和“wtv”?并且有相同的路径来捕获具有未知参数数的较长url


提前感谢

您是否尝试过通过req.params访问

req.params.forEach(function (item) {
  someFn(item);
})
或者只是为了

for (var i = 0, len = req.params.length; i < len; i++) {
  someFn(req.params[i]);
}
for(变量i=0,len=req.params.length;i
您是否尝试过通过req.params获取每个参数

req.params.forEach(function (item) {
  someFn(item);
})
或者只是为了

for (var i = 0, len = req.params.length; i < len; i++) {
  someFn(req.params[i]);
}
for(变量i=0,len=req.params.length;i
ExpressJS路由允许使用通配符,如果您执行以下操作:

this.app.use('/app/fileasset/ui.html/*', function(req,res) {});

然后转到类似于
/app/fileasset/ui.html/test/view/subview/wtv
的url,应使用
“['test/view/subview/wtv']”填充req.params,您可以轻松地在正斜杠上拆分该url。

如果您执行类似操作,ExpressJS路由允许使用通配符:

this.app.use('/app/fileasset/ui.html/*', function(req,res) {});
然后转到类似于
/app/fileasset/ui.html/test/view/subview/wtv
的url,应该使用
“['test/view/subview/wtv']”填充req.params,您可以轻松地在正斜杠上拆分它