在Express中,app.router究竟做了什么? [英] In Express, what does app.router do exactly?
问题描述
当我使用express二进制文件创建一个示例Express应用程序时,引导代码有以下行:
When I create a sample Express application using the express binary, the bootstrap code has these lines:
...
var app = express();
...
app.use(app.router);
我没有找到很多关于app.router的信息。我认为这是处理路由(app.get(),app.post()等)规则的中间件,但是当我删除app.use(app.router)时,这些规则也会被执行;
I didn't find much about app.router. I thought that this is the middleware that handles the routing (app.get(), app.post() etc.) rules, but these rules also get executed when I remove the app.use(app.router); line.
那么这个中间件究竟是什么?
So what is the exact purpuse of this middleware?
推荐答案
p>这是从Express 2.x指南 http://expressjs.com/2x/guide.html
This is from the Express 2.x guide http://expressjs.com/2x/guide.html
请注意使用app.router,可以(可选)用于挂载
应用程序路由,否则第一个调用到app.get(),
app.post()等将挂载路由。
"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。
I suspect this applies to Express 3.x too.
这篇关于在Express中,app.router究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!