express-handlebars icon indicating copy to clipboard operation
express-handlebars copied to clipboard

I'm trying to use router file to handle app.get() but I got error

Open dotku opened this issue 9 years ago • 1 comments

Hi, express-handlebars sample actually runs, but when I convert the app.get() to route file, I got error. Here is my code in /route/index.js

var app = ('../app.js');
app.get('/', function (req, res) {
    res.render('home', {
        title: 'Home'
    });
});

I just take the idea from here: http://stackoverflow.com/questions/25596803/express-4-with-handlebars-add-new-route/25597043#25597043

I also upload my full code to my github branch: https://github.com/dotku/node-study/tree/express_4.x_router

dotku avatar Feb 03 '16 07:02 dotku

I found the answer: instead using app.get(), the router should use router.get()

'use strict';

var express = require('express');
var router = express.Router();

router.get('/', function (req, res) {
    res.render('home', {
        title: 'Home'
    });
});

module.exports = router;

dotku avatar Feb 03 '16 09:02 dotku