[英]Express - set routes in one routes
index.js index.js
app.use('/',wowYeah);
app.use('/lol',wow);
how to use only仅如何使用
routes.js路由.js
app.use('/',wowYeah);
app.use('/lol',wow);
app.use(routes());
but it can't但它不能
how to do it?怎么做?
1 app use for all routes 1 个应用程序用于所有路线
// birds.js file
const express = require('express')
const router = express.Router()
// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
console.log('Time: ', Date.now())
next()
})
// define the home page route
router.get('/', function (req, res) {
res.send('Birds home page')
})
// define the about route
router.get('/about', function (req, res) {
res.send('About birds')
})
module.exports = router
// index.js file
const birds = require('./birds')
// ...
app.use(birds)
for more look documentation .更多查看文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.