2016-01-06 76 views
8

E:\ wordspace \ javascript \ nodejs-demo \ node_modules \ express \ lib \ router \ index.js:502 this.stack.push(layer);about express 4 router and push

TypeError: Cannot read property 'push' of undefined 
    at Function.route (E:\wordspace\javascript\nodejs-demo\node_modules\express\lib\router\index.js:502:13) 
    at Function.proto.(anonymous function) [as get] (E:\wordspace\javascript\nodejs-demo\node_modules\express\lib\router 
\index.js:509:22) 
    at Object.<anonymous> (E:\wordspace\javascript\nodejs-demo\routes\movie.js:6:8) 
    at Module._compile (module.js:435:26) 
    at Object.Module._extensions..js (module.js:442:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:313:12) 
    at Module.require (module.js:366:17) 
    at require (module.js:385:17) 
    at Object.<anonymous> (E:\wordspace\javascript\nodejs-demo\app.js:11:13) 
    at Module._compile (module.js:435:26) 
    at Object.Module._extensions..js (module.js:442:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:313:12) 
    at Module.require (module.js:366:17) 
    at require (module.js:385:17) 

這是我的錯誤報告。

我不能忍受這個問題的根源,需要一種方法來解決它。

這是我的代碼。

movie.js

var Movie = require('./../models/Movie.js'); 
var express = require('express'); 
var router = express.Router; 

/* Get add page. */ 
router.get('/movie/add', function(req, res, next){ 
    if(req.params.name){ 
     return res.render('movie', { 
      title:req.params.name+'|電影|管理|movie.me', 
      label:'編輯電影:'+req.params.name, 
      movie:req.params.name 
     }); 
    } else { 
     return res.render('movie', { 
      title:'新增加|電影|管理|movie.me', 
      label:'新增加電影', 
      movie:false 
     }); 
    } 
}); 

router.post('/movie/add', function(req, res, next){ 
    res.send({'success':true}); 
}); 

app.js

var routes = require('./routes/index'); 
var movie = require('./routes/movie'); 
var users = require('./routes/users'); 

app.use('/', routes); 
app.use('/movie', movie); 
app.use('/users', users); 

請幫助我。

回答

23

路由器是一種功能:var router = express.Router();

+0

對不起,我是一個learner.I不能老是用stackoverflour非常好 –