当我使用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。