我是节点的新手,我正在尝试在 Express 4 中“即时”添加和删除路线。我正在使用 app.use(path,route) 添加它们,并且我能够在应用程序中找到它们._router.stack 数组,但我无法删除特定的路由器。可能吗?我试过 app._router.stack.splice(myRouterIndex,1) 没有成功。
这是我的例子:
for (var i = 0; i < app._router.stack.length; i++) {
if(app._router.stack[i].name=='router') {
console.log(app._router.stack[i].name);
app._router.stack.splice[i,1];
console.log(app._router.stack);
break;
}
}
第二个 console.log(app._router.stack) 打印与第一个完全相同。