我使用快速生成器创建了一个项目。这是我的app.js
var routes = require('./routes/index');
var users = require('./routes/users');
var photo = require('./routes/photo');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
app.use('/photo',photo);
路线下的photo.js
var express = require('express');
var router = express.Router();
router.get('/:id', function(req, res, next) {
res.render('viewPictureDetails', { title: 'ID' });
});
router.get('/sample/123', function(req, res, next) {
res.render('viewPictureDetails', { title: 'Sample' });
});
module.exports = router;
每当我尝试访问localhost:3000 / photo / 123时,它都会进入无限循环。但是/样本工作正常。