在学习一些express相关项目时,github project source中的example常常还是以
express 3.X为基础来举例的, 而其中的
app.use(app.router)有点没头没尾,让人有点困惑。
Express 4
Express 4.0 removes app.router. All middleware (app.use) and routes (app.get et al) are now processed in precisely the order in which they are added.
引用
All routing methods will be added in the order in which they appear. You should not do app.use(app.router). This eliminates the most common issue with Express.
In other words, mixing app.use() and app[VERB]() will work exactly in the order in which they are called.
app.get('/', home);
app.use('/public', require('st')(process.cwd()));
app.get('/users', users.list);
app.post('/users', users.create);
Express 2 and 3
Note that if you don't explicitly use the router, it is implicitly added by Express at the point you define a route (which is why your routes still worked even though you commented out app.use(app.router)).
详见:
http://stackoverflow.com/questions/12695591/node-js-express-js-how-does-app-router-work
分享到:
相关推荐
vue-router.min.js
remount-router:一个用于Express.js简单的基于文件路由器,其中文件更改会自动路由重新安装,而无需重新启动服务器。
redux+react+router+node.js(redux+react router+node.js全栈开发.doc)
vue.min.js和vue-router.min.js
vue路由vue-router.js文件下载
router.config.js
Router-Plugin为一款专用于对360的RePlugin框架使用Router作为兼容适配的框架
在app 模块目录下的build.gradle中添加 dependencies { implementation 'com.safframework.router:saf-router:1.2.1' implementation 'com.safframework.router:saf-router-annotation:1.2.0' annotation...
基于Vue+Vue-Router+Vuex+Element-ui+axios,参考小米商城,实现的电商项目。
术栈 :Vue2 + Webpack + MUI + Node.js(Express) + MongoDB 技术要点: 1.基于vue-cli来搭建单页面应用程序,Webpack进行实时打包 2.使用vue-router配置项目路由,vuex存储公共数据 3.使用MUI框架的图片轮播、...
vue路由器插件 。
小米/红米AC2100
vue-router 3.0.1 版本 , 2018-04-05 最新版本 .
技术栈:vue2.0 vuex vue-router ES6/ES7 webpack lass nodejs express MongoDB
相关博客: 《MySQL集群方案》: https://blog.csdn.net/Zhuge_Dan/article/details/108339965
[海蜘蛛路由操作系统].[Hi-Spider.Router].3.2.7.Hi-Spider.iso 使用老旧的PC重新利用!变废为宝!
JavaScript Applications with Node.js, React, React Native and MongoDB: Design, code, test, deploy and manage in Amazon AWS By 作者: Eric Bush ISBN-10 书号: 0997196661 ISBN-13 书号: 9780997196665 出版...
后端基于Node.js(Koa框架)+Mysql实现。前端包含了11个页面:首页、登录、注册、全部商品、商品详情页、关于我们、我的收藏、购物车、订单结算页面、我的订单以及错误处理页面。实现了商品的展示、商品分类查询、...
精品软件工具--用Vue.js、Vue-router、Vue-i18n、Keen-ui、Webpack、Webpack