【发布时间】:2017-01-04 11:43:32
【问题描述】:
我正在为我的应用程序使用快速路由器。安装特定路线时,我需要运行一个功能。我有两个文件,index.route.js 和 currentUser.route.js
index.route.js
import currentUserRoutes from './currentUser.route';
const router = express.Router();
//mounts the '/me' route on currentUserRoutes
router.use('/me', currentUserRoutes);
export default router;
currentUser.route.js
const router = express.Router();
//line below throws an error
router.on('mount' , () => {console.log("me route mounted")});
router.route('/')
.get(currentUserCtrl.get)
export default router;
它会抛出一个错误,说 router.on 不是函数,我也尝试将 router.on 部分放在 index.route.js 中,但我也遇到了同样的错误。任何帮助将不胜感激。
【问题讨论】:
-
我能够使用
router.all('/*', currentUserCtrl.load);运行我需要的功能。
标签: javascript node.js express routing