node.js – 在Express中,app.router做什么?

当我使用express二进制创建一个示例Express应用程序时,引导代码具有以下这些行:

...

var app = express();
...
app.use(app.router);

我没有发现很多关于app.router。我认为这是处理路由(app.get(),app.post()等)规则的中间件,但是当我删除app.use(app.router)时,这些规则也得到执行。线。

那么这个中间件的确切用途是什么?

解决方法

这是从Express 2.x指南 http://expressjs.com/2x/guide.html

“Note the use of app.router,which can (optionally) be used to mount
the application routes,otherwise the first call to app.get(),
app.post(),etc will mount the routes.”

我怀疑这也适用于Express 3.x。

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...