路由:
ffmpeg
路线:
app.use('/cms/', require('./routes/index.js'));
app.use('/cms/schools/', require('./routes/schools.js'));
目标:我想将/cms/
/cms/schools/
/cms/schools/:schoolId/classes/:classId
分成两个文件:./routes/schools.js
和schools.js
,以便更好地了解。
问题:我希望保留前缀路径schools_classes.js
,但不知道如何正确拆分。
如何构建文件以达到预期目标? 提前谢谢!
修改1 : 我尝试了以下,这是行不通的(重复的路由前缀):
/cms/schools/
答案 0 :(得分:0)
你可以使用快速路由器来做到这一点:
路线:
const schoolsRouter = require('./routes/schools');
app.use('/cms/schools', schoolsRouter)
./路由/学校/ index.js:
const express = require('express');
const router = express.Router();
router.use('/',require('./schools _controller.js'));
router.use('/:schoolId/classes/:classId', require ('./schools_classes_controller.js'));
module.exports = router;
您可以在此处查看整个路由器文档:http://expressjs.com/en/4x/api.html#router